博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Misha and Changing Handles
阅读量:6791 次
发布时间:2019-06-26

本文共 2526 字,大约阅读时间需要 8 分钟。

Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.

Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.

Input

The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests.

Next q lines contain the descriptions of the requests, one per line.

Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20.

The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handle new is not used and has not been used by anyone.

Output

In the first line output the integer n — the number of users that changed their handles at least once.

In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old and new, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order.

Each user who changes the handle must occur exactly once in this description.

Example

Input
5 Misha ILoveCodeforces Vasya Petrov Petrov VasyaPetrov123 ILoveCodeforces MikeMirzayanov Petya Ivanov
Output
3 Petya Ivanov Misha MikeMirzayanov Vasya VasyaPetrov123 题意理解:将指令进行多次修改; 解题步骤:利用map容器可以水出;
#include
#include
#include
using namespace std;int main(){ int m; map
mp; cin >> m; while (m--) { string a, b; cin >> a >> b; map
::iterator p; for (p = mp.begin(); p != mp.end(); p++) { if (p->second == a) { p->second = b; break; } } if (p == mp.end()) mp[a] = b; } cout << mp.size() << endl; map
::iterator k; for (k = mp.begin(); k != mp.end(); k++) cout << k->first << " " << k->second << endl; cout << endl; system("pause "); return 0;}

用size可以统计容器的个数;

转载于:https://www.cnblogs.com/kangdong/p/8454433.html

你可能感兴趣的文章
RedHat系统怎么设置或更改屏幕分辨率
查看>>
spring mybatis整合配置文件
查看>>
02(maven+SSH)网上商城项目实战之数据库设计(PMD)
查看>>
谈Docker安全合规建设
查看>>
LR中的关联
查看>>
nginx配置php连接
查看>>
调整状态学会放下与五月份的个人计划
查看>>
Oracle中如何将姓名中有空格的字段更新成没有空格的?
查看>>
xp扩容C盘后盘符丢失的资料怎么找到
查看>>
CVE-2017-12617
查看>>
SSH管理服务
查看>>
废旧行业迎来春天 环保部重启绿色GDP研究
查看>>
监控——JVM监控安装
查看>>
Working with System Properties
查看>>
为什么我墙裂建议大家使用枚举来实现单例
查看>>
记一次阿里云服务器安装Python的血泪史
查看>>
c++函数模块与其相关内容
查看>>
ssh防止暴力破解之fail2ban
查看>>
LNMP基础安装配置
查看>>
借助Gradle Plugin解决模块化开发中模块如何对外暴露接口
查看>>