Misha and Changing Handles
来源:互联网 发布:火凤凰云计算拖欠工资 编辑:程序博客网 时间:2024/05/29 04:18
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.
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 andnew, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Stringsold and new are distinct. The lengths of the strings do not exceed20.
The requests are given chronologically. In other words, by the moment of a query there is a single person with handleold, and handle new is not used and has not been used by anyone.
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 handleold, and after all the requests are completed, his handle isnew. You may output lines in any order.
Each user who changes the handle must occur exactly once in this description.
5Misha ILoveCodeforcesVasya PetrovPetrov VasyaPetrov123ILoveCodeforces MikeMirzayanovPetya Ivanov
3Petya IvanovMisha MikeMirzayanovVasya VasyaPetrov123
代码:
#include<stdio.h>#include<string.h>using namespace std;struct node{char old[25];char now[25];}e[1005];int cnt;int Find(char *a){for(int i=1;i<cnt;i++)if(!strcmp(e[i].now,a)) return i;return 0;}int main(){int T;scanf("%d",&T);cnt=1;while(T--){char a[25],b[25];scanf("%s %s",a,b);int k=Find(a);if(k) strcpy(e[k].now,b);else {strcpy(e[cnt].old,a);strcpy(e[cnt].now,b);cnt++;}}printf("%d\n",cnt-1);for(int i=1;i<cnt;i++)printf("%s %s\n",e[i].old,e[i].now);return 0;}
- Misha and Changing Handles
- Misha and Changing Handles
- Misha and Changing Handles
- Misha and Changing Handles
- B - Misha and Changing Handles
- B. Misha and Changing Handles
- Misha and Changing Handles CodeForces
- codeforce B. Misha and Changing Handles
- CodeForces - 501B Misha and Changing Handles
- Codeforces 501 B - Misha and Changing Handles
- CF 501B Misha and Changing Handles
- CodeForces 501B Misha and Changing Handles
- codeforces 501B Misha and Changing Handles
- CodeForces 501B Misha and Changing Handles
- codeforce285A--Misha and Changing Handles-字符串
- 【codeforces 510 B Misha and Changing Handles】
- Misha and Changing Handles(字符串修改)
- Codeforces 501B - Misha and Changing Handles (STL)
- 表格全选与全不选,选中删除
- Pandas日期数据处理:如何按日期筛选、显示及统计数据
- WCF读取数据库中的数据传输至WPF显示
- ipython notebook 下包含python2, python3两个kernel
- Linux(C/C++)下的文件操作open、fopen与freopen
- Misha and Changing Handles
- Wannafly挑战赛1-C.MMset2(LCA)
- [LeetCode] 34. Search for a Range
- Window使用问题积累
- java知识点概括
- HTML
- 软考完美收官
- 神经网络反向传播(相关公式)
- 关于代码节省时间的优化---优雅点