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 ...
随机推荐
- RTM,RTW,GA等软件版本号详解
一直以来,对于新手而言,软件的版本号都是个比较困扰人的问题,什么Beta.RC,再来个RTM.RTW....头大了吧?RTM和RTW有什么区别?借此机会,就给大家介绍一下这方面的小知识吧. 1.软件开 ...
- pycharm双击无响应,打不开问题解决办法
之前好好的pycharm,突然双击打不开了,怎么办? 亲测有效方案: 第一步:进入如下路径,找到cmd.exe,右键选择“以管理员身份运行”: 第二步:在打开的cmd窗口中,输入 netsh wins ...
- 32.Longest Valid Parentheses---dp
题目链接:https://leetcode.com/problems/longest-valid-parentheses/description/ 题目大意:找出最长的括号匹配的子串长度.例子:&qu ...
- ssh使两台机器建立连接
ssh利用口令建立连接过程: 客户端--> 发送连接请求 --> 远程主机 --> 返回远程主机的公钥 --> 公钥加密客户端私钥+客户端公钥返回远程主机 --> 远程主 ...
- POJ 3087 Shuffle'm Up (模拟+map)
题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...
- K8S网络排故障一则--iptables规则
这个故障源起来在k8s上同时安装ceph群集(测试的时候机器不多啊) 当这两者都OK之后,原来k8s上的服务实例,则有的通,有的不通了. ==================== 所有可能的故障点,f ...
- 【LOJ】#2010. 「SCOI2015」小凸解密码
题解 断环为链,把链复制两份 用set维护一下全是0的区间,然后查找x + n / 2附近的区间,附近各一个过不去,最后弃疗了改为查附近的两个,然后过掉了= = 熟练掌握stl的应用,你值得拥有(雾 ...
- C# 字符串提取数字
转自:http://www.cnblogs.com/dolphin-gjh/p/6121792.html 一.使用正则表达式 1 string str = "sztq数字提取123sztq数 ...
- Unity 游戏开发技巧集锦之使用cookie类型的纹理模拟云层的移动
Unity 游戏开发技巧集锦之使用cookie类型的纹理模拟云层的移动 使用cookie类型的纹理模拟云层的移动 现实生活中,当阳光直射大地,而天空中又有很多云时,云层的影子总是会投射在大地上,风吹着 ...
- 修复mysql
REPAIR TABLE TABLENAME 或 REPAIR TABLE TABLENAME USE_FRM