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

题意:按照顺序与人聊天,每次聊天都将当前对象放到最前端,其余的后移一位。看到下面的说用到二分想了半天...难道是把人名和数字组成一组?想想限时3秒感觉还是STL走起吧(没办法智商无力),也是第一次用stack,刚开始Runing test 3转半天吓得我以为超时了

代码:

#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<cmath>
#include<stack>
using namespace std;
int main(void)
{
stack<string>slist;
map<string,int>mlist;
int n;
while (cin>>n)
{
string s;
while (n--)
{
cin>>s;
slist.push(s);
mlist[s]=1;//记录一下
}
while (!slist.empty())
{
if(mlist[slist.top()]==1)//若还没输出过,就输出
{
cout<<slist.top()<<endl;
mlist[slist.top()]--;//可输出次数减1,代表已输出
slist.pop();
}
else
slist.pop();//直接扔掉
}
}
return 0;
}

VK Cup 2016 - Qualification Round 1——B. Chat Order(试手stack+map)的更多相关文章

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

  2. VK Cup 2016 - Qualification Round 1 (Russian-Speaking Only, for VK Cup teams) B. Chat Order 水题

    B. Chat Order 题目连接: http://www.codeforces.com/contest/637/problem/B Description Polycarp is a big lo ...

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

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

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

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

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

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

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

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

随机推荐

  1. 给广大码农分享福利:一个业界良心的github仓库,中文计算机资料

    我今天查资料时无意发现的,https://github.com/CyC2018/CS-Notes 这个仓库包含了下列几个维度的计算机学习资料: 深受国内程序员喜爱,已经有超过3万多star了. 1. ...

  2. Round #322 (Div. 2) 581D Three Logos (模拟)

    先枚举两个矩形,每个矩形横着放或竖着放,把一边拼起来, 如果不是拼起来有缺口就尝试用第三个矩形去补. 如果没有缺口就横着竖着枚举一下第三个矩形和合并的矩形x或y拼接. #include<bits ...

  3. Beta冲刺(周五)

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1 这个作业要求在哪里 https://edu.cnblo ...

  4. xpath定位和css定位对比

    xpath定位和css定位对比   实际项目中使用较多的是xpath定位和css定位.XPath是XML文档中查找结点的语法,换句话就是通过元素的路径来查找这个元素.xpath比较强大,而css选择器 ...

  5. 2018.2.09 php学习(二)

    1.用索引提高效率: 索引是表的一个概念部分,用来提高检索数据的效率,ORACLE使用了一个复杂的自平衡B-tree结构. 通常,通过索引查询数据比全表扫描要快. 当ORACLE找出执行查询和Upda ...

  6. hadoop相关资料集锦

    1 Hadoop集群系列集锦http://www.cnblogs.com/xia520pi/archive/2012/04/08/2437875.html 2 Hadoop和MapReduce详解ht ...

  7. JavaScript深入浅出第2课:函数是一等公民是什么意思呢?

    摘要: 听起来很炫酷的一等公民是啥? <JavaScript深入浅出>系列: JavaScript深入浅出第1课:箭头函数中的this究竟是什么鬼? JavaScript深入浅出第2课:函 ...

  8. 虚拟机设置NAT

    需要开启虚拟机网络相关服务, 安装虚拟网卡, 还有必须安装 VMware Tools VMware虚拟机下实现NAT方式上网1. 把你的虚拟网卡VMnet8设置为自动获得IP.自动获得DNS服务器,启 ...

  9. cocos2d-x的基本动作2

    1.基本动作 Cocos2d提供的基本动作:瞬时动作.延时动作.运作速度. 瞬时动作:就是不需要时间,马上就完成的动作.瞬时动作的共同基类是 InstantAction. Cocos2d提供以下瞬时动 ...

  10. 【原】基于matlab的蓝色车牌定位与识别---绪论

    本着对车牌比较感兴趣,自己在课余时间摸索关于车牌的定位与识别,现将自己所做的一些内容整理下,也方便和大家交流. 考虑到车牌的定位涉及到许多外界的因素,因此有必要对车牌照的获取条件进行一些限定: 一.大 ...