VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) B. Chat Order 水题
B. Chat Order
题目连接:
http://www.codeforces.com/contest/637/problem/B
Description
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.
Input
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.
Output
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Sample Input
4
alex
ivan
roman
ivan
Sample Output
ivan
roman
alex
Hint
题意
有一个人,有一个队列。
然后现在依次插入n个单词,如果这个单词已经在队列中了,那就把这个单词从原来位置扔到队列首。
否则就把这个单词扔到队首。
问你最后这个队列长啥样。
题解:
其实倒着输出就好了,然后开个map记录一下vis就行了。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 200005;
string s[maxn];
map<string,int>vis;
int main()
{
int n;scanf("%d",&n);
for(int i=1;i<=n;i++)
cin>>s[i];
for(int i=n;i;i--)
{
if(vis[s[i]])continue;
cout<<s[i]<<endl;
vis[s[i]]=1;
}
}
VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) B. Chat Order 水题的更多相关文章
- VK Cup 2016 - Qualification Round 2 B. Making Genome in Berland
今天在codeforces上面做到一道题:http://codeforces.com/contest/638/problem/B 题目大意是:给定n个字符串,找到最短的字符串S使得n个字符串都是这个字 ...
- VK Cup 2016 - Qualification Round 2 D. Three-dimensional Turtle Super Computer 暴力
D. Three-dimensional Turtle Super Computer 题目连接: http://www.codeforces.com/contest/638/problem/D Des ...
- VK Cup 2016 - Qualification Round 2 C. Road Improvement dfs
C. Road Improvement 题目连接: http://www.codeforces.com/contest/638/problem/C Description In Berland the ...
- VK Cup 2016 - Qualification Round 2 B. Making Genome in Berland 水题
B. Making Genome in Berland 题目连接: http://www.codeforces.com/contest/638/problem/B Description Berlan ...
- VK Cup 2016 - Qualification Round 2 A. Home Numbers 水题
A. Home Numbers 题目连接: http://www.codeforces.com/contest/638/problem/A Description The main street of ...
- VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) D. Running with Obstacles 贪心
D. Running with Obstacles 题目连接: http://www.codeforces.com/contest/637/problem/D Description A sports ...
- VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) C. Promocodes with Mistakes 水题
C. Promocodes with Mistakes 题目连接: http://www.codeforces.com/contest/637/problem/C Description During ...
- VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) A. Voting for Photos 水题
A. Voting for Photos 题目连接: http://www.codeforces.com/contest/637/problem/A Description After celebra ...
- VK Cup 2016 - Qualification Round 1——A. Voting for Photos(queue+map)
A. Voting for Photos time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- perl6正则 4: before / after 代码断言: <?{}> / <!{}>
<?before> <? befor XXX> 某字符在 xxx 之前 <?after > <?after XXX> 某字符之后有XXX 对应的取反分别 ...
- 对RSA的认识
#没有经过专业老师的指导,所以您在阅读本文时建议参考即可. 学习视屏:https://www.youtube.com/watch?v=TqX0AHHwRYQ https://www.youtub ...
- [005] unique_sub_string
[Description] Given a string, find the largest unique substring. e.g. str[] = "asdfghjkkjhgf&qu ...
- linux编程之main()函数启动过程【转】
转自:http://blog.csdn.net/gary_ygl/article/details/8506007 1 最简单的程序 1)编辑helloworld程序,$vim helloworld. ...
- PHP--- JSON和数组的转换
一.json_encode() <?php $arr =array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5); echo json_ ...
- caffe多个gpu数据合并到一起
当多GPU树形拓扑构建完毕,数据预缓冲到GPU显存,开始进入多GPU并行训练.Caffe的Solver提供了两个用于多GPU训练的回调函数:on_start()和on_gradient_ready() ...
- SNMP AGENT函数介绍
http://wenku.baidu.com/view/6a7903a9d1f34693daef3e9f.html 一. SNMP AGENT在SNMP框架中的位置 1.1 SNMP是被广泛接受并投 ...
- 获取ios设备系统信息的方法 之 [UIDevice currentDevice]
获取iphone的系统信息使用[UIDevice currentDevice],信息如下: [[UIDevice currentDevice] systemName]:系统名称,如iPhone OS ...
- Linux文件访问和日志
一.文件系统创建一个文件的过程假设我们想要新增一个文件,此时文件系统的行为是:先确定用户对于欲新增文件的目录是否具有 w 与 x 的权限,若有的话才能新增:根据 inode bitmap 找到没有使用 ...
- 在WebClient类中保持Session
string url = context.Request["url"]; WebClient MyWebClient = new WebClient(); // 获取或设置用于向I ...