有N个改名的动作,输出改完名的最终结果。

拿map做映射

 #include <iostream>
#include <map>
#include <string>
using namespace std;
map<string,string> mp;
map<string,int> vis;
int n;
string s1,s2;
int main()
{
cin>>n;
map<string,string>::iterator it;
for(int i=;i<=n;i++)
{
cin>>s1>>s2;
if(!vis[s1]&&!vis[s2])
{
vis[s1]=; vis[s2]=; mp[s1]=s2;
}
else if(vis[s1]&&!vis[s2])
{
vis[s2]=;
for(it=mp.begin();it!=mp.end();it++)
{
if(it->second==s1)
{
it->second=s2; break;
}
}
}
}
cout<<mp.size()<<endl;
for(it=mp.begin();it!=mp.end();it++)
{
cout<<it->first<<" "<<it->second<<endl;
}
}

CodeForces 501B - Misha and Changing Handles的更多相关文章

  1. CodeForces 501B Misha and Changing Handles(STL map)

    Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user ...

  2. 【CodeForces - 501B 】Misha and Changing Handles(map)

    Misha and Changing Handles CodeForces原题是英文,这里就直接上中文好了,翻译不是太给力,但是不影响做题 ^▽^ Description  神秘的三角洲里还有一个传说 ...

  3. 字符串处理 Codeforces Round #285 (Div. 2) B. Misha and Changing Handles

    题目传送门 /* 题意:给出一系列名字变化,问最后初始的名字变成了什么 字符串处理:每一次输入到之前的找相印的名字,若没有,则是初始的,pos[m] 数组记录初始位置 在每一次更新时都把初始pos加上 ...

  4. ACM Misha and Changing Handles

    Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user ...

  5. B. Misha and Changing Handles

    B. Misha and Changing Handles time limit per test 1 second memory limit per test 256 megabytes input ...

  6. codeforces 501 B Misha and Changing Handles 【map】

    题意:给出n个名字变化,问一个名字最后变成了什么名字 先用map顺着做的,后来不对, 发现别人是将变化后的那个名字当成键值来做的,最后输出的时候先输出second,再输出first 写一下样例就好理解 ...

  7. Misha and Changing Handles

    Description Misha hacked the Codeforces site. Then he decided to let all the users change their hand ...

  8. codeforces 501C. Misha and Forest 解题报告

    题目链接:http://codeforces.com/problemset/problem/501/C 题目意思:有 n 个点,编号为 0 - n-1.给出 n 个点的度数(即有多少个点跟它有边相连) ...

  9. Codeforces 832D - Misha, Grisha and Underground

    832D - Misha, Grisha and Underground 思路:lca,求两个最短路的公共长度.公共长度公式为(d(a,b)+d(b,c)-d(a,c))/2. 代码: #includ ...

随机推荐

  1. NSNotification消息

    注册消息 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(方法) name:@"消息名字&q ...

  2. linux android ndk

    Android调用so库, so库是c语言编写, 在linux 64位系统+ndk(32位)生成 lib*.so (32位) 1. 所需软件环境: 1)so库开发环境 操作系统: Redhat Ser ...

  3. (转)JAVA路径问题及命令行编译运行基础(linux下)

    原地址: http://blog.csdn.net/biaobiaoqi/article/details/6846274 java的运行机制的基本概念: 源文件 也就是我们熟知的.java文件. 类文 ...

  4. 关于安卓的log学习

    什么时候会产生log文件? 1. 程序异常退出 Uncaused Exception. 2. 程序强制关闭 Force Closed(FC). 3. 程序无响应 Application No Resp ...

  5. Sublime 插件安装

    转http://www.cnblogs.com/Rising/p/3741116.html

  6. awk之基本信息

    awk 利用RS来分割文本,分割后形成一条一条的record awk 利用FS来分割record,分割后形成一段一段的field field由一串一串的字符串构成 默认的RS是换行符 默认的FS是空格 ...

  7. HDU 1172 猜数字(DFS)

    猜数字 Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  8. Ubuntu14.04安装PostpreSQL9.3.5记录

    安装参考:http://www.postgresql.org/download/linux/ubuntu/ y@y:~$ sudo apt-get install postgresql-9.3 pos ...

  9. GitHub好站点

    https://github.com/XingCloud/stream_processor

  10. scheme一页纸教程

    这是一个大学教授写的,非常好,原文:http://classes.soe.ucsc.edu/cmps112/Spring03/languages/scheme/SchemeTutorialA.html ...