cf 637B

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

Copy

4
alex
ivan
roman
ivan

output

Copy

ivan
roman
alex

input

Copy

8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina

output

Copy

alina
maria
ekaterina
darya

Note

 

 

意:根据一天的对话,倒着给出说话人的名字。让你正着输出说第一次话的人的名字。比如 abacdabacd,正着说话 =dcab=dcab, 最后一个aa是aa第二次说话,不用输出。

直接正着来,一个名字只输出一次,后面的跳过。
 

就是把输入的字符串倒着输出就行了,加个map判重

#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <set>
#include <ctime>
#include <cmath>
#include <cctype>
using namespace std;
#define maxn 200005
#define LL long long
int cas=1,T;
map<string,int> visit;
string s[maxn];
int main()
{
	int n;
	while (scanf("%d",&n)!=EOF)
	{
		for (int i = 0;i<n;i++)
		{
			cin >> s[i];
	        //visit[s[i]]=1;		
		}
		for (int i = n-1;i>=0;i--)
		{
			if (!visit[s[i]])
				cout << s[i] << endl;
			visit[s[i]]=1;
		}
	}
	//freopen("in","r",stdin);
	//scanf("%d",&T);
	//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值