304037: CF776A. A Serial Killer

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A Serial Killer

题意翻译

我们所深爱的侦探夏洛克,目前正试图抓住一个每天都要杀死一个人的强迫症杀手。通过运用其自身高超的推理能力,夏洛克目前对于凶手挑选下一位受害者的策略了然于心。 当第一天降临,杀手首先从两位潜在的受害者中随机挑选一位脸黑人士进行暗杀,并且每当一位潜在的受害者倒下,都会有另一人取代该受害者之位置,成为新的潜在受害者(幸免于难的那位仍然留在潜在受害者名单上)。可以确定这位杀手每天都会重复这一过程,这样一来,杀手每天都有两个潜在的受害者可供选择进行暗杀。好在夏洛克知道最初的两个潜在受害者是谁,并且,夏洛克知道发生杀人事件的当天的死者是谁以及新的潜在受害者是谁。 显然,好心的你需要每天帮助夏洛克列出每天的的潜在受害者名单,这样一来夏洛克就能从中观察到一些奇妙的规律。 输入格式: 输入的第一行包含两个名字(每个名字的长度不超过10),这是最初的两个潜在受害者。下一行包含整数天数n (1<=n<=1000)。 接下来的n行每行包含两个名字(每个名字的长度不超过10),第一个是当天被谋杀的人(死者),第二个是取代死者成为新的潜在受害者的人。 输入格式是一致的,也就是说,一名死者肯定是当时的两个潜在受害者之一。此外,所有名字都可以保证是不同的,并均由小写英文字母组成。 输出格式: 输出n+1行,每行输出当天的两位潜在受害者的名字(这两个名字的输出顺序可以随意) 题目下方说明: 如样例1所示,杀手从ross和rachel开始杀起。 第一天结束后,ross不幸被杀而joey接替。 第二天结束后,rachel不幸被杀而phoebe接替。 第三天结束后,phoebe不幸被杀而monica接替。 第四天结束后,monica不幸被杀而chandler接替。

题目描述

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.

输入输出格式

输入格式


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

输入输出样例

输入样例 #1

ross rachel
4
ross joey
rachel phoebe
phoebe monica
monica chandler

输出样例 #1

ross rachel
joey rachel
joey phoebe
joey monica
joey chandler

输入样例 #2

icm codeforces
1
codeforces technex

输出样例 #2

icm codeforces
icm technex

说明

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.

Input

题意翻译

我们所深爱的侦探夏洛克,目前正试图抓住一个每天都要杀死一个人的强迫症杀手。通过运用其自身高超的推理能力,夏洛克目前对于凶手挑选下一位受害者的策略了然于心。 当第一天降临,杀手首先从两位潜在的受害者中随机挑选一位脸黑人士进行暗杀,并且每当一位潜在的受害者倒下,都会有另一人取代该受害者之位置,成为新的潜在受害者(幸免于难的那位仍然留在潜在受害者名单上)。可以确定这位杀手每天都会重复这一过程,这样一来,杀手每天都有两个潜在的受害者可供选择进行暗杀。好在夏洛克知道最初的两个潜在受害者是谁,并且,夏洛克知道发生杀人事件的当天的死者是谁以及新的潜在受害者是谁。 显然,好心的你需要每天帮助夏洛克列出每天的的潜在受害者名单,这样一来夏洛克就能从中观察到一些奇妙的规律。 输入格式: 输入的第一行包含两个名字(每个名字的长度不超过10),这是最初的两个潜在受害者。下一行包含整数天数n (1<=n<=1000)。 接下来的n行每行包含两个名字(每个名字的长度不超过10),第一个是当天被谋杀的人(死者),第二个是取代死者成为新的潜在受害者的人。 输入格式是一致的,也就是说,一名死者肯定是当时的两个潜在受害者之一。此外,所有名字都可以保证是不同的,并均由小写英文字母组成。 输出格式: 输出n+1行,每行输出当天的两位潜在受害者的名字(这两个名字的输出顺序可以随意) 题目下方说明: 如样例1所示,杀手从ross和rachel开始杀起。 第一天结束后,ross不幸被杀而joey接替。 第二天结束后,rachel不幸被杀而phoebe接替。 第三天结束后,phoebe不幸被杀而monica接替。 第四天结束后,monica不幸被杀而chandler接替。

加入题单

算法标签: