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
  1. ross rachel
    4
    ross joey
    rachel phoebe
    phoebe monica
    monica chandler
output
  1. ross rachel
    joey rachel
    joey phoebe
    joey monica
    joey chandler
input
  1. icm codeforces
    1
    codeforces technex
output
  1. 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.

题意:看样列

解法:没啥说的

  1. #include<bits/stdc++.h>
  2. typedef long long LL;
  3. typedef unsigned long long ULL;
  4. typedef long double LD;
  5. using namespace std;
  6. int main(){
  7. string s1,s2;
  8. cin>>s1>>s2;
  9. cout<<s1<<" "<<s2<<endl;
  10. int n;
  11. cin>>n;
  12. for(int i=;i<=n;i++){
  13. string s3,s4;
  14. cin>>s3>>s4;
  15. if(s3==s1){
  16. s1=s4;
  17. }else{
  18. s2=s4;
  19. }
  20. cout<<s1<<" "<<s2<<endl;
  21. }
  22. return ;
  23. }

ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) A的更多相关文章

  1. 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 ...

  2. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem 2-SAT

    题目链接:http://codeforces.com/contest/776/problem/D D. The Door Problem time limit per test 2 seconds m ...

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

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

  4. 【2-SAT】【并查集】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) D. The Door Problem

    再来回顾一下2-SAT,把每个点拆点为是和非两个点,如果a能一定推出非b,则a->非b,其他情况同理. 然后跑强连通分量分解,保证a和非a不在同一个分量里面. 这题由于你建完图发现都是双向边,所 ...

  5. 【枚举】【前缀和】【map】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals

    处理出前缀和,枚举k的幂,然后从前往后枚举,把前面的前缀和都塞进map,可以方便的查询对于某个右端点,有多少个左端点满足该段区间的和为待查询的值. #include<cstdio> #in ...

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

    Moriarty has trapped n people in n distinct rooms in a hotel. Some rooms are locked, others are unlo ...

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

    Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an aff ...

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

    Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her s ...

  9. ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals

    感觉自己做有关区间的题目方面的思维异常的差...有时简单题都搞半天还完全没思路,,然后别人提示下立马就明白了...=_= 题意:给一个含有n个元素的数组和k,问存在多少个区间的和值为k的次方数. 题解 ...

随机推荐

  1. win7 64位系统与Ubuntu14.04 64位系统双系统安装【转】

    本文转载自:http://blog.csdn.net/strugglepeach/article/details/51260886 Window 7 + Ubuntu 双系统安装   硬件: Thin ...

  2. centos 7 / 6 smokeping安装

    官网 值得拥有:http://oss.oetiker.ch/smokeping/doc/reading.en.html 安装依赖包 1 2 yum -y install perl perl-Net-T ...

  3. 为 Android 平台开发一个输入法

    学习目标: 实现新的输入法 学习目的: 掌握Android输入法框架 学习收获: Android 1.5 新特色之一就是输入法框架(Input Method Framework,IMF),正是它的出现 ...

  4. MySQL丨5.6版本插入中文显示问号解决方法

    解决办法: 1.找到安装目录下的my-default.ini 这个配置文件 2.copy一份粘贴到同目录下 另命名为my.ini 3.在my.ini 配置下加上下面几句代码 并保存 [mysql]de ...

  5. cowboy跨域请求处理

    这几日在使用cowboy开发https服务器的过程中碰到几个问题,这里随手记录一下. 1)如果返回错误ERR_EMPTY_RESPONSE,那么可能是web服务器被关闭了. 2)如果返回错误ERR_C ...

  6. 51nod1674:区间的价值2(分治,利用&和|的收敛性)

    lyk拥有一个区间. 它规定一个区间的价值为这个区间中所有数and起来的值与这个区间所有数or起来的值的乘积. 例如3个数2,3,6.它们and起来的值为2,or起来的值为7,这个区间对答案的贡献为2 ...

  7. SPOJ:Red John is Back(DP)

    Red John has committed another murder. But this time, he doesn't leave a red smiley behind. What he ...

  8. HihoCoder 1590 : 紧张的会议室(区间最大+离散化)

    时间限制:20000ms 单点时限:2000ms 内存限制:256MB 描述 小Hi的公司最近员工增长迅速,同时大大小小的会议也越来越多:导致公司内的M间会议室非常紧张. 现在小Hi知道公司目前有N个 ...

  9. hdu 最短路模板题 java

    最短路 Problem Description 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在 ...

  10. TimeUtils(没试过)

    package util; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.ParseExc ...