B - Chat Order -- (各种映射乱搞)

来源:互联网 发布:百万公众网络答题活动 编辑:程序博客网 时间:2024/06/05 10:30
B - Chat Order
Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status

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

Input
4alexivanromanivan
Output
ivanromanalex
Input
8alinamariaekaterinadaryadaryaekaterinamariaalina
Output
alinamariaekaterinadarya

最开始开结构体数组映射乱搞,果断超时,各种生活不能自理
超时代码:
#include <stdio.h>#include <string.h>struct p{char s[12];int flag;}p[200005];int main(){int n,i,j;scanf("%d",&n);for(i=1;i<=n;i++){p[i].flag=0;}scanf("%s",p[1].s);for(i=2;i<=n;i++){scanf("%s",p[i].s);for(j=i-1;j>=1;j--){if(!p[j].flag)if(strcmp(p[i].s,p[j].s)==0){p[j].flag=1;break;}}}for(i=n;i>=1;i--){if(p[i].flag==0)printf("%s\n",p[i].s);}return 0;}

最后试着用STL,,,,第一次用map映射。。。貌似很好用的啊
#include <cstdio>#include <iostream>#include <string>#include <stack>#include <map>using namespace std;int main(){int n;stack<string>S;map<string,int>M;string s;scanf("%d",&n);while(n--){cin>>s;S.push(s);M[s]=1;}while(!S.empty()){if(M[S.top()]==1){cout<<S.top()<<endl;M[S.top()]--;S.pop();}elseS.pop();}return 0;}


0 0
原创粉丝点击