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 ;
}

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

CodeForces776-A.Serial Killer-string的更多相关文章

  1. 【codeforces 776A】A Serial Killer

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

  2. Codeforces 776 A.Serial Killer-String直接比较是否相同

    A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  3. Linux/drivers/usb/serial/ftdi_sio.c

    Linux/drivers/usb/serial/ftdi_sio.h /* 2 * Driver definitions for the FTDI USB Single Port Serial Co ...

  4. Serial.begin

    串口波特率的设置:通常我们使用Serial.begin(speed)来完成串口的初始化,这种方式,只能配置串口的波特率. 使用Serial.begin(speed, config)可以配置数据位.校验 ...

  5. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)

    前四题比较水,E我看出是欧拉函数傻逼题,但我傻逼不会,百度了下开始学,最后在加时的时候A掉了 AC:ABCDE Rank:182 Rating:2193+34->2227 终于橙了,不知道能待几 ...

  6. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A map B贪心 C思路前缀

    A. A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A

    Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each ...

  8. CodeForces contest/776 A+B+C题解

    ICM Technex 2017 and Codeforces Round #400 (Div. 1 +Div.2,combined) A. A Serial Killer 谜一样的题意:每天从两个人 ...

  9. Codeforces Round #400 (Div. 1 + Div. 2, combined)——ABCDE

    题目戳这里 A.A Serial Killer 题目描述似乎很恶心,结合样例和样例解释猜测的题意 使用C++11的auto可以来一手骚操作 #include <bits/stdc++.h> ...

随机推荐

  1. Inception使用详解

    一.Inception简介一款用于MySQL语句的审核的开源工具,不但具备自动化审核功能,同时还具备执行.生成对影响数据的回滚语句功能. 基本架构: 二.Inception安装 1.软件下载 下载链接 ...

  2. xamarin android menu的用法

    在Android中的菜单有如下几种: OptionMenu:选项菜单,android中最常见的菜单,通过Menu键来调用 SubMenu:子菜单,android中点击子菜单将弹出一个显示子菜单项的悬浮 ...

  3. HTML5 给图形绘制阴影(绘制五角星示例)

    几个属性 shadowOffsetX:阴影的横向位移量. shadowOffsetY:阴影的纵向位移量. shadowColor:阴影的颜色. shadowBlur:阴影的模糊范围. 属性说明 sha ...

  4. 在win7下用net命令无法实现对用户的创建(未完成)

    ============================================================================================= 201307 ...

  5. K:java中枚举的常见用法

    用法一:常量   在JDK1.5 之前,我们定义常量都是: public static fianl.....现在好了,有了枚举,可以把相关的常量分组到一个枚举类型里,而且枚举提供了比常量更多的方法. ...

  6. 前端学习_01_css网页布局

    引子 之前也自己陆陆续续地学了一些web方面的知识,包括前段和后端都有涉及到,自己也比较感兴趣,感谢peter老师,愿意无偿提供从零开始的教学,之前也看过peter老师的一些视频,节奏非常适合我,决心 ...

  7. Android View的事件冲突

    上一篇博客讨论了一下view中的事件分发,既然存在事件分发的过程,那么也就可能存在着冲突.常见的由以下三种形式的冲突.(外面叫做OuterViewGroup,包裹在里面的叫做InnerViewGrou ...

  8. Life in Changsha 第二次scrum冲刺

    第二次冲刺   第二次冲刺任务 设计留言板功能. 用户故事 用户打开“生活在长大”的界面 程序首页展示校园服务,论坛等相关信息 用户选择留言板 程序界面跳转 用户查看留言,并可以输入留言内容 提交后留 ...

  9. 高效的CSS代码(2)

    ——阅读笔记,欢迎纠错^_^ 内容比较零散..... 1.让浮动元素的父容器根据元素的高度而自适应高度的方法: <div class="clearfix"><di ...

  10. vuex 基本用法、兄弟组件通信,参数传递

    vuex主要是是做数据交互,父子组件传值可以很容易办到,但是兄弟组件间传值,需要先将值传给父组件,再传给子组件,异常麻烦. vuex大概思路:a=new Vue(),发射数据'msg':a.$emit ...