[CodeForces
来源:互联网 发布:232数据盒rs-100 编辑:程序博客网 时间:2024/06/16 01:59
Link: http://codeforces.com/problemset/problem/637/B
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
The first line contains integer n (1 ≤ n ≤ 200 000) — the number of Polycarpus' messages. Next n lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
4alexivanromanivan
ivanromanalex
8alinamariaekaterinadaryadaryaekaterinamariaalina
alinamariaekaterinadarya
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
- alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
- ivan
- alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
- roman
- ivan
- alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
- ivan
- roman
- alex
Code:
#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>#include<algorithm>#include<iostream>#include<queue>#include<stack>#include<map>using namespace std;map<string,int> visit; //标记是否访问过string name[200005];int main(){int n;while(~scanf("%d",&n)){for(int i=1;i<=n;i++)cin >> name[i];for(int i=n;i>=1;i--){if(!visit[name[i]])cout << name[i] << endl;visit[name[i]]=1;}}return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- jq 中^表示字符串的开始
- Java数字操作类
- 算法复杂性
- Java日期处理类
- 存储过程实现分页
- [CodeForces
- Ctrl+滚轮 禁止页面缩放
- Java比较器
- Linux 入门 -- root boot
- Java正则表达式
- Java反射机制
- Android WebView用法
- 计蒜客ACM ICPC 2017 Warmup Contest 9--B题-Battle Simulation
- Gradle2.0用户指南翻译——第八章.依赖管理基础