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 水题的更多相关文章

  1. VK Cup 2016 - Qualification Round 2 B. Making Genome in Berland

    今天在codeforces上面做到一道题:http://codeforces.com/contest/638/problem/B 题目大意是:给定n个字符串,找到最短的字符串S使得n个字符串都是这个字 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. ConcurrentHashMap分析

    1.ConcurrentHashMap锁分段技术                     ConcurrentHashMap使用锁分段技术,首先将数据分成一段一段地存储,然后给每一段数据配一把锁,当一 ...

  2. 76.ZYNQ-用PS控制DDR3内存读写

    本编文章的目的主要用简明的方法对DDR3进行读写,当然这种方式每次读写都需要CPU干预,效率是比较低的,但是这是学习的过程吧. 本系列文章尽可能的让每一个实验都相对独立,过程尽可能保证完整性,保证实验 ...

  3. 【swupdate文档 四】SWUpdate:使用默认解析器的语法和标记

    SWUpdate:使用默认解析器的语法和标记 介绍 SWUpdate使用库"libconfig"作为镜像描述的默认解析器. 但是,可以扩展SWUpdate并添加一个自己的解析器, ...

  4. React 16 源码瞎几把解读 【二】 react组件的解析过程

    一.一个真正的react组件编译后长啥样? 我们瞎几把解读了react 虚拟dom对象是怎么生成的,生成了一个什么样的解构.一个react组件不光由若干个这些嵌套的虚拟dom对象组成,还包括各种生命周 ...

  5. 10.python3标准库--加密

    ''' 加密可以保护消息安全,以便验证其正确性并保护消息不被截获. python的加密支持包括hashlib和hmac,hashlib使用标准算法生成消息内容签名,hmac则用于验证消息在传输过程中未 ...

  6. ELK简单使用

    原作者:http://www.cnblogs.com/snidget/p/6269383.html ELK ELK是什么? Elasticsearch LogStash Kibana     1,简单 ...

  7. 查看wtmp(登陆信息的内容)

      /var/log/wtmp文件的作用     /var/log/wtmp也是一个二进制文件,记录每个用户的登录次数和持续时间等信息.   查看方法:   可以用last命令输出当中内容: debi ...

  8. 3.rabbitmq 发布/订阅

    1. 发布者 #coding:utf8 import pika import json import sys message = ''.join(sys.argv[1:]) or "hell ...

  9. UVA 11624 Fire!(两次BFS+记录最小着火时间)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  10. python抓取链家房源信息

    闲着没事就抓取了下链家网的房源信息,抓取的是北京二手房的信息情况,然后通过网址进行分析,有100页,并且每页的url都是类似的 url = 'https://bj.lianjia.com/ershou ...