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 ...
随机推荐
- oracle 初探内存结构
数据库的存储机构 分为 逻辑存储结构 和 物理存储结构 逻辑存储结构: 数据库.表空间.段.区.块 物理存储结构: 数据库.控制文件.数据文件.初始化参数文件.OS块等. 一个区只能在 ...
- hdu1215七夕节
Problem Description 七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!" ...
- OpenCV——分水岭算法
分水岭算法,是一种基于拓扑理论的数学形态学的分割方法,其基本思想是把图像看作是测地学上的拓扑地貌,图像中每一点像素的灰度值表示该点的海拔高度,每一个局部极小值及其影响区域称为集水盆,而集水盆的边界则形 ...
- Nubiers to follow
VGG Andrea Vedaldi Berkeley Trevor Darrell Jeff Donahue Ross Girshick Sergio Guadarrama Stanford And ...
- linux命令--virtualenv
virtualenv可以搭建虚拟且独立的python环境,可以使每个项目环境与其他项目独立开来,保持环境的干净,解决包冲突问题. 一.安装virtualenv virtualenv实际上是一个pyth ...
- python中发送get或post请求
示例 get import httplib import uuid import time url = "/KM/test.php?time=" url += str(int(ti ...
- FTP之主动模式vs被动模式
背景说明 最近有个项目涉及到FTP的上传下载问题.在本地开发好的程序测试的时候能正常获取FTP内容,但一放到生产上却显示connection timeout,无法连接.经过一些研究,发现是防火墙造成的 ...
- winform 读取保存配置文件
原文连接: public static string fileName = System.IO.Path.GetFileName(Application.ExecutablePath); ...
- php 写队列
这里不得不提到php的数组函数真的是太强大了 队列是先进先出 那么对于数组来说就尾部插入,头部拿出 这里提供方法 尾部插入 我们知道有一个函数array_push 头部拿出 array_shift($ ...
- Mysql MEMORY 引擎
CREATE TABLE `m` ( `) unsigned NOT NULL AUTO_INCREMENT, `name` ) NOT NULL, `ctime` ) NOT NULL, `ltim ...