CodeForces776-A.Serial Killer-string
2 seconds
256 megabytes
standard input
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.
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.
ross rachel
4
ross joey
rachel phoebe
phoebe monica
monica chandler
ross rachel
joey rachel
joey phoebe
joey monica
joey chandler
icm codeforces
1
codeforces technex
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.
这个题就是找下面的名字,有一样的就替换掉。
代码:
#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的更多相关文章
- 【codeforces 776A】A Serial Killer
[题目链接]:http://codeforces.com/contest/776/problem/A [题意] 这个杀手每天会除掉一个人; 这个杀手每天都有两个目标; 给你它杀人的日志,以及这个人被杀 ...
- Codeforces 776 A.Serial Killer-String直接比较是否相同
A Serial Killer time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- 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 ...
- Serial.begin
串口波特率的设置:通常我们使用Serial.begin(speed)来完成串口的初始化,这种方式,只能配置串口的波特率. 使用Serial.begin(speed, config)可以配置数据位.校验 ...
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)
前四题比较水,E我看出是欧拉函数傻逼题,但我傻逼不会,百度了下开始学,最后在加时的时候A掉了 AC:ABCDE Rank:182 Rating:2193+34->2227 终于橙了,不知道能待几 ...
- 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 ...
- 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 ...
- CodeForces contest/776 A+B+C题解
ICM Technex 2017 and Codeforces Round #400 (Div. 1 +Div.2,combined) A. A Serial Killer 谜一样的题意:每天从两个人 ...
- Codeforces Round #400 (Div. 1 + Div. 2, combined)——ABCDE
题目戳这里 A.A Serial Killer 题目描述似乎很恶心,结合样例和样例解释猜测的题意 使用C++11的auto可以来一手骚操作 #include <bits/stdc++.h> ...
随机推荐
- iOS 进阶—— iOS 内存管理
1 似乎每个人在学习 iOS 过程中都考虑过的问题 alloc retain release delloc 做了什么? autoreleasepool 是怎样实现的? __unsafe_unretai ...
- [Maximize ∑arr[i]*i of an Array]
Given an array of N integers. Your task is to write a program to find the maximum value of ∑arr[i]*i ...
- c#发展前景
根据育龙网资料评价显示:C#几乎集中了所有关于软件开发和软件工程研究的最新成果:面向对象.类型安全.组件技术.自动内存管理.跨平台异常处理.版本控制.代码安全管理…….尽管像很多人注意到的一样,罗列上 ...
- NumPy学习笔记 三 股票价格
NumPy学习笔记 三 股票价格 <NumPy学习笔记>系列将记录学习NumPy过程中的动手笔记,前期的参考书是<Python数据分析基础教程 NumPy学习指南>第二版.&l ...
- windows server数据库备份
@echo off //设置生成文件名字 set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%"//使用mysqldump输出sql文件 cesec ...
- javamelody 使用
javamelody 扩展API如何获取监控参数 https://github.com/javamelody/javamelody/wiki/ExternalAPI#json
- Python初体验
今天开始所有的工作脚本全都从perl转变到python,开发速度明显降低了不少,相信以后随着熟练度提升会好起来.贴一下今天一个工作代码,由于之前去一家小公司测序时,序列长度竟然都没有达到要求,为了之后 ...
- Linux下查找文件的方法
在Linux环境下查找一个文件的方法:find 路径 -name 'filename',filename不清楚全名的话可以用*号进行匹配,如“tomcat.*”.如果不清楚路径的话可以用"/ ...
- 对《cookie之困》的一些总结与思考
0x00 前言 早些时候在gayhub翻安全大会的paper,翻到了kcon的一些paper. https://github.com/knownsec/KCon 从前辈们的paper中学到了不少,也产 ...
- 那些年原生js实现的楼层跳转
最近做一个需求~~楼层跳转(京东.淘宝侧边导航),由于现在项目都用框架,所以 jquery是不能再用了,只好自己原生写一个,其实实现起来很简单,无非就是获取到每个楼层距离文档顶部的距离,然后通过控制滚 ...