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. 从PEP-8学习Python编码风格

    (搬运自我在SegmentFault的博客) 关于空行 类与顶级函数(top-level function)的定义之间应当空两行. 类中的方法之间应当空一行. 方法中的逻辑部分之间可以空一行. 关于原 ...

  2. duboo 配置文件

    官方文档 http://dubbo.apache.org/en-us/docs/user/quick-start.html 自己的 <?xml version="1.0" e ...

  3. python 基础之格式化输出

    字符占位符%s #_cvvh:"chenxi" #date: 2019/6/24 print ('chhjg') # 格式化输出 name = input("Name:& ...

  4. MySQL 数据备份与还原的示例代码

    MySQL 数据备份与还原的示例代码 这篇文章主要介绍了MySQL 数据备份与还原的相关知识,本文通过示例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下 一.数据备份 1.使用 ...

  5. Chunky Monkey-freecodecamp算法题目

    Chunky Monkey(猴子吃香蕉, 分割数组) 要求 把一个数组arr按照指定的数组大小size分割成若干个数组块. 思路 利用size值和while语句确定切割数组的次数(定义temp将siz ...

  6. 关于C与C++的区别

    笔者介绍:姜雪伟,IT公司技术合伙人,IT高级讲师,CSDN社区专家,特邀编辑,畅销书作者,已出版书籍:<手把手教你架构3D游戏引擎>电子工业出版社和<Unity3D实战核心技术详解 ...

  7. NOIP模拟赛 不等数列

    [题目描述] 将1到n任意排列,然后在排列的每两个数之间根据他们的大小关系插入“>”和“<”.问在所有排列中,有多少个排列恰好有k个“<”.答案对2012取模. [输入格式] 第一行 ...

  8. poj1654 Area

    题目描述: vjudge POJ 题解: 本以为是水题结果是神题 计算几何求多边形面积. 考虑到结果一定是整数或者整数/2,我们应该用long long 来存…… 用double会死…… 还有日常只能 ...

  9. cin 和 getline 混用中需要注意的问题

    这段时间在刷题过程中遇到一个cin和getline混合使用中的问题,解决之后记录如下: 先来看一段代码 #include <iostream> #include <string> ...

  10. Centos7系统下安装Docker

    1.确定你的Linux系统是Centos7 命令:cat /etc/redhat-release 2.yum安装gcc相关 1.配置好Centos7能上外网. 2.yum -y install gcc ...