题目链接:

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. java实体类如果不重写toString方法,会如何?

    先认识一下Object Object 类的 toString 方法 返回一个字符串,该字符串由类名(对象是该类的一个实例).at 标记符“@”和此对象哈希码的无符号十六进制表示组成.换句话说,该方法返 ...

  2. python学习 05 函数switch功能

    1.python没有switch功能,利用字典实现 如果用if else,可行但是效率不高

  3. xcode ERROR ITMS

    1.ERROR ITMS-90046 /90085: "Invalid Code Signing Entitlements. Your application bundle's signat ...

  4. List和Set排序的实现

    List.Set.Map的区别 List和Set继承了Collection接口. List以特定索引来存取元素,可以有重复元素.Set不能存放重复元素(用对象的equals()方法来区分元素是否重复) ...

  5. vptr

    #include <stdio.h> class Point3d { public: virtual ~Point3d(){} public: static Point3d origin; ...

  6. jquery 通过属性选择器获取input不为disabled的对象

    $("input[id^='input_001']:not(:disabled)").each(function(){ console.log(this); });

  7. 【BZOJ3651】网络通信 LCT

    [BZOJ3651]网络通信 Description 有一个由M 条电缆连接的 N 个站点组成的网络.为了防止垄断,由 C 个公司控制所有的电缆,规定任何公司不能控制连接同一个站点的两条以上的电缆(可 ...

  8. K - Max Sum Plus Plus

    K - Max Sum Plus Plus Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  9. 解决iOS11 UIScrollView下移问题

    iOS11 系统为UIScrollView增加一个contentInsetAdjustmentBehavior属性,默认为UIScrollViewContentInsetAdjustmentAutom ...

  10. Future Promise 模式(netty源码9)

    netty源码死磕9  Future Promise 模式详解 1. Future/Promise 模式 1.1. ChannelFuture的由来 由于Netty中的Handler 处理都是异步IO ...