I love Codeforces
Posted yiyunwang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了I love Codeforces相关的知识,希望对你有一定的参考价值。
Among participants of programming contests at codeforces.com the following tradition is common: whenever a participant falls in love with another participant, he changes his nickname to ?I_love_<nickname of the participant he fell in love with>?. Unfortunately, for technical reasons site administration has lost the current nicknames of participants who had changed their nicknames recently, but the information about who of them fell in love with whom remains. Now the administration needs to write a program for determining the current nickname of the given participant. It should be noted that due to the small bug in the database structure different participants can have the same nicknames on this site.
The first line contains a single integer n (2?≤?n?≤?200000) — the number of participants.
In the next n lines initial nicknames of participants are given. Each nickname is a non-empty string of length at most 24 characters, consisting only of uppercase and lowercase Latin letters and also underscores. Some nicknames can coincide.
The next line contains a single integer m (1?≤?m?≤?200000) — the number of records that one of the participants fell in love with another participant.
In the next m lines pairs of integers aj and bj, separated by a space, are given (1?≤?aj,?bj?≤?n, aj?≠?bj) — a record that the aj-th participant fell in love with the bj-th participant and changed his nickname correspondingly. Participants are numbered from one in the order their initial nicknames are given. Renamings occur in the order they are given.
In the only line output the final nickname of the first participant after all renamings.
5
anonymous
natalia
LeBron
Tanya_Romanova
MikeMirzayanov
6
1 2
3 4
2 1
4 3
1 4
3 2
I_love_I_love_I_love_Tanya_Romanova
5
anonymous
natalia
LeBron
Tanya_Romanova
MikeMirzayanov
3
2 1
1 2
1 5
I_love_MikeMirzayanov
2
MikhailRubinchik
evol_I
1
1 2
I_love_evol_I
题目大意比较简单,模拟就可以了,记录每次字符串前面I_love_的个数 level.以及最底下的字符串。最后输出即可
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; string s[n+1]; for(int i=1;i<=n;i++){ cin>>s[i]; } int m; cin>>m; int a[m][2]; for(int i=0;i<m;i++){ cin>>a[i][0]>>a[i][1]; } int x=1; int count=0; for(int i=m-1;i>=0;i--){ if(a[i][0]==x){ x=a[i][1]; count++; } } for(int i=0;i<count;i++){ cout<<"I_love_"; } cout<<s[x]; return 0; }
以上是关于I love Codeforces的主要内容,如果未能解决你的问题,请参考以下文章
codeforces#FF(div2) DZY Loves Sequences
A. Little C Loves 3 I Codeforces Round #511 (Div. 2) 数学
codeforces#FF(div2) D DZY Loves Modification