题目链接:

B. Chat Order

time limit per test

3 seconds
memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
input
4
alex
ivan
roman
ivan
output
ivan
roman
alex
input
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
output
alina
maria
ekaterina
darya
Note

In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:

  1. alex

Then Polycarpus writes to friend by name "ivan" and the list looks as follows:

  1. ivan
  2. alex

Polycarpus writes the third message to friend by name "roman" and the list looks as follows:

  1. roman
  2. ivan
  3. 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:

  1. ivan
  2. roman
  3. alex

题意:按给的顺序联系他的朋友,把最后的列表打印出来;

思路:从后往前,没出现的输出,出现的就continue,记录是否出现过可以用map;

AC代码:

#include <bits/stdc++.h>
using namespace std;
const int N=2e5+;
string str[N];
map<string,int>mp;
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
cin>>str[i];
}
for(int i=n-;i>=;i--)
{
if(!mp[str[i]])
{
cout<<str[i]<<"\n";
mp[str[i]]=;
}
}
return ;
}

codeforces 637B B. Chat Order(map,水题)的更多相关文章

  1. codeforces 677A A. Vanya and Fence(水题)

    题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...

  2. Codeforces Beta Round #37 A. Towers 水题

    A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...

  3. Educational Codeforces Round 7 B. The Time 水题

    B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...

  4. Educational Codeforces Round 7 A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...

  5. Codeforces Testing Round #12 A. Divisibility 水题

    A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...

  6. CodeForces 690C1 Brain Network (easy) (水题,判断树)

    题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...

  7. Codeforces - 1194B - Yet Another Crosses Problem - 水题

    https://codeforc.es/contest/1194/problem/B 好像也没什么思维,就是一个水题,不过蛮有趣的.意思是找缺黑色最少的行列十字.用O(n)的空间预处理掉一维,然后用O ...

  8. codeforces 659C C. Tanya and Toys(水题+map)

    题目链接: C. Tanya and Toys time limit per test 1 second memory limit per test 256 megabytes input stand ...

  9. codeforces Gym 100187H H. Mysterious Photos 水题

    H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

随机推荐

  1. 文件大小转换(b,kb,M,GB/TB)

    //转换单位 setupSize(1111111111111); function setupSize($fileSize) { $size = sprintf("%u", $fi ...

  2. TensorFlow CNN 測试CIFAR-10数据集

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50738311 1 CIFAR-10 数 ...

  3. IOS程序国际化

    1.1 新建一个Single View app模版项目,命名为Localization. 1.2 新建后,可以看到工作目录结构文件如下,单击InfoPlist.strings,查看右边的属性,在Loc ...

  4. 如何通过Git命令行把代码提交到github上

    1.http://www.cnblogs.com/leesf456/p/5169765.html   参考博客 背景:最近入手了mac,看见mac上的大神都是在用git命令行推代码,我很羡慕有木有,好 ...

  5. POJ1850&&POJ1496

    Code Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9236   Accepted: 4405 Description ...

  6. 九度OJ 1209:最小邮票数 (遍历)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2252 解决:741 题目描述: 有若干张邮票,要求从中选取最少的邮票张数凑成一个给定的总值.     如,有1分,3分,3分,3分,4分五 ...

  7. rate limiter - system design

    1 问题 Whenever you expose a web service / api endpoint, you need to implement a rate limiter to preve ...

  8. 【python】-- socketserver

    socketserver SocketServer服务端内部使用 IO多路复用 以及 “多线程” 和 “多进程” ,从而实现并发处理多个客户端请求.即:每个客户端请求连接到服务器时,Socket服务端 ...

  9. NOIP考前划水

    NOIP考前划水 君指先跃动の光は.私の一生不変の信仰に.唯私の超電磁砲永世生き! 要开始背配置了? 3行不谢. (setq c-default-style "awk") (glo ...

  10. 几则js表达式

    过滤大段文本里的标签.标签格式 <...>,如下匹配标签然后替换成空 校验邮箱是否符合: 去掉行首行尾空格: 检测字符串是否包含中文:(utf8编码)