A Serial Killer

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.

The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim.

You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.

Input

First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days.

Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person.

The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.

Output

Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.

Examples
Input
ross rachel
4
ross joey
rachel phoebe
phoebe monica
monica chandler
Output
ross rachel
joey rachel
joey phoebe
joey monica
joey chandler
Input
icm codeforces
1
codeforces technex
Output
icm codeforces
icm technex
Note

In first example, the killer starts with ross and rachel.

After day 1, ross is killed and joey appears.

After day 2, rachel is killed and phoebe appears.

After day 3, phoebe is killed and monica appears.

After day 4, monica is killed and chandler appears.

这个题就是找下面的名字,有一样的就替换掉。

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1e4+;
int main(){
string a[N],b[N];
string aa,bb;
int n,i;
cin>>aa>>bb;
cin>>n;
for(i=;i<n;i++)
cin>>a[i]>>b[i];
cout<<aa<<" "<<bb<<endl;
for(i=;i<n;i++){
if(a[i]==aa){
aa=b[i]; //哇,这里智障了,一开始写成aa==b[i]了,多写了一个=, 
cout<<aa<<" "<<bb<<endl;
continue;
}
if(a[i]==bb){
bb=b[i];
cout<<aa<<" "<<bb<<endl;
continue;
}
}
return ;
}

最近写的长得最好看的一个代码

Codeforces 776 A.Serial Killer-String直接比较是否相同的更多相关文章

  1. 【codeforces 776A】A Serial Killer

    [题目链接]:http://codeforces.com/contest/776/problem/A [题意] 这个杀手每天会除掉一个人; 这个杀手每天都有两个目标; 给你它杀人的日志,以及这个人被杀 ...

  2. codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题

    http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...

  3. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  4. Codeforces Round #617 (Div. 3) String Coloring(E1.E2)

    (easy version): 题目链接:http://codeforces.com/contest/1296/problem/E1 题目一句话就是说,两种颜色不同的字符可以相互换位, 问,对这字符串 ...

  5. codeforces 709D D. Recover the String(构造)

    题目链接: D. Recover the String time limit per test 1 second memory limit per test 256 megabytes input s ...

  6. codeforces 710E E. Generate a String(dp)

    题目链接: E. Generate a String time limit per test 2 seconds memory limit per test 512 megabytes input s ...

  7. Codeforces 710 E. Generate a String (dp)

    题目链接:http://codeforces.com/problemset/problem/710/E 加或者减一个字符代价为x,字符数量翻倍代价为y,初始空字符,问你到n个字符的最小代价是多少. d ...

  8. codeforces 676C C. Vasya and String(二分)

    题目链接: C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input sta ...

  9. codeforces 598B Queries on a String

    题目链接:http://codeforces.com/problemset/problem/598/B 题目分类:字符串 题意:给定一个串,然后n次旋转,每次给l,r,k,表示区间l到r的字符进行k次 ...

随机推荐

  1. NET中解决KafKa多线程发送多主题

    NET中解决KafKa多线程发送多主题 一般在KafKa消费程序中消费可以设置多个主题,那在同一程序中需要向KafKa发送不同主题的消息,如异常需要发到异常主题,正常的发送到正常的主题,这时候就需要实 ...

  2. C# 托盘图标闪烁

    在用户正在登录QQ或者使用Firemail邮件系统自动收取邮件的时候,托盘图标会闪动提示用户正在运行的任务.闪动图标可以使用定时切换托盘图标的方式实现,托盘图标可以从ImageList控件中获取.在I ...

  3. android 与 小米1S刷机学习

    本文内容为本博客作者原创,转载请注明出处或者发私信. [名词] 1.ROM包 :安卓手机系统,以.ZIP结尾,类似windows的 win7系统包,300M-700M不止 2.卡刷(Recovery模 ...

  4. [IOI2007 D1T1]Miners 矿工配餐

    题目大意:有$2$个煤矿,$n$天.每天给一个煤矿送餐(共有有$3$种餐),价值为它与前面两次送餐(如果有的话)不同的种类数.最大化价值. 题解:看到只有三种餐,考虑状压$DP$.$f_{i,j,k, ...

  5. 斜率dp+cdq分治

    写在前面 这个东西应该是一个非常重要的套路......所以我觉得必须写点什么记录一下,免得自己忘掉了 一直以来我的斜率dp都掌握的不算很好......也很少主动地在比赛里想到 写这个的契机是noi.a ...

  6. ldconfig用法小记

    By francis_hao    Aug 4,2017   ldconfig:配置运行时动态链接库 概述 /sbin/ldconfig [ -nNvXV ] [ -f conf ] [ -C cac ...

  7. Codeforces Round #525 (Div. 2)A. Ehab and another construction problem

    A. Ehab and another construction problem 题目链接:https://codeforc.es/contest/1088/problem/A 题意: 给出一个x,找 ...

  8. 桥接物理网卡,pipwork指定ip,外网连接,研究salt+docker

    1.桥接物理网卡: 首先下载工具: yum -y install --enablerepo=epel bridge-utils 停止服务: 983 systemctl stop docker 删除do ...

  9. node安装

    由于Node.js平台是在后端运行JavaScript代码,所以,必须首先在本机安装Node环境. 安装Node.js 目前Node.js的最新版本是7.6.x.首先,从Node.js官网下载对应平台 ...

  10. 51Nod-1586-约数和

    #include <cstdio> using namespace std; typedef long long ll; ; int n, q; int cnt[MAXN]; ll a[M ...