CodeForces 501B - Misha and Changing Handles
有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的更多相关文章
- 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 ...
- 【CodeForces - 501B 】Misha and Changing Handles(map)
Misha and Changing Handles CodeForces原题是英文,这里就直接上中文好了,翻译不是太给力,但是不影响做题 ^▽^ Description 神秘的三角洲里还有一个传说 ...
- 字符串处理 Codeforces Round #285 (Div. 2) B. Misha and Changing Handles
题目传送门 /* 题意:给出一系列名字变化,问最后初始的名字变成了什么 字符串处理:每一次输入到之前的找相印的名字,若没有,则是初始的,pos[m] 数组记录初始位置 在每一次更新时都把初始pos加上 ...
- ACM Misha and Changing Handles
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user ...
- B. Misha and Changing Handles
B. Misha and Changing Handles time limit per test 1 second memory limit per test 256 megabytes input ...
- codeforces 501 B Misha and Changing Handles 【map】
题意:给出n个名字变化,问一个名字最后变成了什么名字 先用map顺着做的,后来不对, 发现别人是将变化后的那个名字当成键值来做的,最后输出的时候先输出second,再输出first 写一下样例就好理解 ...
- Misha and Changing Handles
Description Misha hacked the Codeforces site. Then he decided to let all the users change their hand ...
- codeforces 501C. Misha and Forest 解题报告
题目链接:http://codeforces.com/problemset/problem/501/C 题目意思:有 n 个点,编号为 0 - n-1.给出 n 个点的度数(即有多少个点跟它有边相连) ...
- Codeforces 832D - Misha, Grisha and Underground
832D - Misha, Grisha and Underground 思路:lca,求两个最短路的公共长度.公共长度公式为(d(a,b)+d(b,c)-d(a,c))/2. 代码: #includ ...
随机推荐
- OD调试1--第一个win32程序
OD调试一:第一个Win32程序的修改 在软件开发的过程中,程序员会使用一些调试工具,以便高效地找出软件中存在的错误.而在逆向分析领域,分析者也会利用相关的调试工具来分析软件的行为并验证分析结果.由于 ...
- ConcurrentQueue对列的基本使用方式
队列(Queue)代表了一个先进先出的对象集合.当您需要对各项进行先进先出的访问时,则使用队列.当您在列表中添加一项,称为入队,当您从列表中移除一项时,称为出队. ConcurrentQueue< ...
- noip2015 提高组day1、day2
NOIP201505神奇的幻方 试题描述 幻方是一种很神奇的N∗N矩阵:它由数字 1,2,3,……,N∗N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方 ...
- [music]<蔷薇>
我在虾米音乐听到一首好听的歌曲<蔷薇>,一起来听吧!http://www.xiami.com/song/386109?ref=aother LOFTER:我们的故事 http://us ...
- JuPyter(IPython) Notebook中通过pip安装第三方Python Module
JuPyter(IPython) Notebooks中使用pip安装Python的模块 刚开始接触JuPyter Notebook的时候觉得这是个不错的写技术博客的工具,可以很直观的把代码和结果结合在 ...
- ruby更换为淘宝的源
我们在使用gem更新的时候,经常会为速度抓狂,其实gem默认的源是https://rubygems.org,比较慢众所周至的原因了. 可以将源更换到国内的taobao源 查看当前有的源 gem sou ...
- Spyder调试错误-"TypeError: decoding Unicode is not supported"
这是Spyder 2.7.4版本的一个Bug,升级到最新版本(2.7.9)即可. pip install --upgrade spyder Reference: https://github.com/ ...
- project euler 25 fibonacci
数学方法: Saying that a number contains 1000 digits is the same as saying that it's greater than 10**999 ...
- 动态绑定ReportViewer控件之经验总结
以上两篇文章已经很丰富了,但是照做一遍不行,检查了N遍还是不行,就是找不出问题原因,总是提示“尚未为数据源“DataSet1_DataTable1”提供数据源实例.”这主要是说在为ReportView ...
- GetCurrentDirectory、SetCurrentDirectory和GetModuleFileName
DWORD GetCurrentDirectory( DWORD nBufferLength, // size of directory buffer LPTSTR lpBuffer // ...