codeforce B. Misha and Changing Handles
题目链接: http://codeforces.com/contest/501/problem/B
5 Misha ILoveCodeforces Vasya Petrov Petrov VasyaPetrov123 ILoveCodeforces MikeMirzayanov Petya Ivanov
3 Petya Ivanov Misha MikeMirzayanov Vasya VasyaPetrov123
*********代码:
#include<iostream>#include<cstdio>#include<cstring>#include<string>using namespace std;const int maxn=1005;int main(){string Name1[maxn],Name2[maxn];string s1,s2;int m;cin>>m;int cnt=0;while(m--){cin>>s1>>s2;int gg=0;for(int i=1;i<=cnt;i++)if(s1==Name2[i]){gg=i;break;}if(!gg){Name1[++cnt]=s1;Name2[cnt]=s2;continue;}Name2[gg]=s2;}printf("%d\n",cnt);for(int i=1;i<=cnt;i++)cout<<Name1[i]<<" "<<Name2[i]<<endl;return 0;}
**********map 的做法:
#include<iostream>
# include<cstdio>
#include<cstring>
#include<string>
# include<map>
using namespace std;
map<string ,string> m;
int main()
{string s1,s2;int n;cin>>n;for(int i=0; i<n; i++){cin>>s1>>s2;if(m.find(s1)==m.end())m[s2]=s1;else{m[s2]=m[s1];m.erase(s1);}}cout<<m.size()<<endl;for(map<string ,string>::iterator i=m.begin(); i!=m.end(); i++)cout<<i->second<<" "<<i->first<<endl;return 0;
}
#include<cstdio>
#include<string>
#include<map>
using namespace std;
map<string,string> m;
map<string,string>::iterator it;
int main()
{int q;char pre[25],now[25];scanf("%d",&q);while(q--){scanf("%s%s",pre,now);pair<string,string> tmp=make_pair(now,pre);it=m.find(pre);if(it!=m.end()){tmp.second=it->second; m.erase(it);}m.insert(tmp);}printf("%d\n",m.size());for( it=m.begin(); it!=m.end(); ++it)printf("%s %s\n",it->second.c_str(),it->first.c_str());
}
codeforce B. Misha and Changing Handles相关推荐
- 【Codeforces】501B Misha and Changing Handles(map)
http://codeforces.com/problemset/problem/501/B map的应用,让新的名字作为key值,旧的名字作为value值,然后一一对应.如果这个旧名字不在map里, ...
- CodeForces 501B——Misha and Changing Handles
题意:给定一些姓名的原来姓名和修改后的名字,由于一个名字可以被修改多次,所以求所有用户的初始姓名和当前姓名. 思路:暴力.数据量很小,对于每次修改直接判断其是否有原来的名字即可,有的话更新,没有就作为 ...
- CodeForces 501B - Misha and Changing Handles
有N个改名的动作,输出改完名的最终结果. 拿map做映射 1 #include <iostream> 2 #include <map> 3 #include <strin ...
- Codeforces--501B--Misha and Changing Handles
题目描述: Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A ...
- 很有趣的STL初学资料
1.泛型程序设计简介与迭代器的介绍 2.常见的STL容器及其例题应用(UVA10474,UVA101,UVA10815,UVA156,UVA540,UVA136 HDU1027,CF501B,HDU1 ...
- codeforce #501 c Misha and Forest
Let's define a forest as a non-directed acyclic graph (also without loops and parallel edges). One d ...
- Codeforce 1255 Round #601 (Div. 2) A. Changing Volume (贪心)
Bob watches TV every day. He always sets the volume of his TV to bb. However, today he is angry to f ...
- Codeforces 504 A (Round #285 div.1 A) Misha and Forest
Codeforces Round #285 (Div.1) A Misha and Forest 水题水题水-- 题意:给你一些点,给出他们连通了多少个点以及这些点的下标的异或值,让你找出一个图 题解 ...
- 树链剖分 + 后缀数组 - E. Misha and LCP on Tree
E. Misha and LCP on Tree Problem's Link Mean: 给出一棵树,每个结点上有一个字母.每个询问给出两个路径,问这两个路径的串的最长公共前缀. analyse: ...
最新文章
- mysql57 修改root密码,MySQL 5.7.x修改root默认密码(CentOS下)
- Swift 4正式发布,新功能概览
- Kafka基础知识入门
- javascript 高级程序设计学习笔记(面向对象的程序设计) 1
- 分布式事务理论-二阶段提交(Two-phase Commit)
- c# asp.net mvc 开发的正方教务助手(一)
- vmware创建虚拟机并安装centos7系统
- 唐云峰:想当科学家的怪极客
- Vue 监视属性 watch
- setTimeOut传参数
- 隐马尔可夫模型通俗导论
- 20169217 2016-2017-2 《网络攻防实践》第四周学习总结
- linux直播电视软件下载,周末了!通过Linux Mint开发的IPTV播放器观看海量国内外直播电视...
- Kodak Preps 8 for Mac(专业拼版软件)
- 我的毕业设计后端技术栈
- python基础资料(Learn|Codecademy好用的工具)
- keras UserWarning: Discrepancy between trainable weights and collected trainable weigh...
- 如何在Microsoft Word中转录音频
- 安卓手机刷机liunx服务器_Android手机通用刷机教程,小白必看!
- 深度信念神经网络DBN最通俗易懂的教程
热门文章
- 绿卡日记:2020-10-29
- Python问题:bash: syntax error near unexpected token `newline'
- swift之inout
- CentOS 7修改hostname
- python正则分辨逗号去除数字千位符
- Java之路:变量作用域
- liquibase mysql_liquibase使用教程
- c语言二维数组和多维数组笔记
- 我的世界java版种子掠夺者,《我的世界》1.14最适合新手的全能种子 你想要的冒险这里都有...
- 微信小程序实现window经典的扫雷游戏