有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. C# 4.0 并行计算部分

    C# 4.0 并行计算部分   c#linq算法多线程list微软   目录(?)[-] C 40 并行计算部分 一简单使用 二 并行循环的中断和跳出 三并行循环中为数组集合添加项 四返回集合运算结果 ...

  2. myeclipse8.6 for spring环境配置

     

  3. java基础知识1

    58.线程的基本概念.线程的基本状态以及状态之间的关系线程指在程序执行过程中,能够执行程序代码的一个执行单位,每个程序至少都有一个线程,也就是程序本身.Java中的线程有四种状态分别是:运行.就绪.挂 ...

  4. (原)使用mkl中函数LAPACKE_sgesv计算矩阵的逆矩阵

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5578027.html 参考文档:mkl的说明文档 lapack_int LAPACKE_sgesv(i ...

  5. 2015.4.2-SQL 简单语句(一)

    1.创建一个student表 create table student_masen( sno char(4) not null primarykey sname nchar(10) not null ...

  6. MAC OS中使用ll,la命令

    在linux下习惯了使用ll.la等ls别名 用mac os发现没有这样的命令,很不方便. 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可:alias ll='ls ...

  7. c++基础五个题(三)

    一.一个对象访问普通函数和虚函数的时候,哪一个更快? 访问普通函数更快,因为普通成员函数在编译阶段已经被确定,因此在访问时直接调用对应地址的函数,而虚函数在调用时,需要首先在虚函数表中查找虚函数所在的 ...

  8. Pie(hdu 1969 二分查找)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  9. HtmlAttribute HTML属性处理类

    HtmlAttribute 在HtmlAgilityPack扮演的是一个HTML代码属性的容器,同时提供了用于处理HTML属性的一些功能. 一.属性 int Line { get; } 获取文档中的此 ...

  10. SVD学习

    前言: 上一次写了关于PCA与LDA的文章,PCA的实现一般有两种,一种是用特征值分解去实现的,一种是用奇异值分解去实现的.在上篇文章中便是基于特征值分解的一种解释.特征值和奇异值在大部分人的印象中, ...