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. Iterator中的next()

    DBExchangeMoney类: 1 package com.ch.test15; import java.sql.DriverManager; import java.sql.ResultSet; ...

  2. 重温Javascript(三)-继承

    继承 1.原型链继承 基本思想是利用原型让一个引用类型继承另一个引用类型的属性和方法.每个构造函数都有一个原型对象,原型对象都包含一个指向构造函数的指针,而实例都包含一个指向原型对象的内部指针.让原型 ...

  3. Vue -- 仿照商城分类竖向侧边栏点击居中效果(横向原理相同)

    github代码地址 效果图

  4. java基础—线程(一)

    一.线程的基本概念

  5. *运算和&运算

    /* &:取地址运算符 *:指针运算符(或称为间接运算符),取指针所指向的对象的内容 */ int a,b; int *pointer_1, *pointer_2; pointer_1 = & ...

  6. 【bitset 技巧 分块】bzoj5087: polycomp

    神仙zq发现了${n^2\sqrt n}\over 32$做法 Description 你有三个系数为0,1的多项式f(x),g(x),h(x) 求f(g(x)) mod h(x) 为方便起见,将答案 ...

  7. Docker DockerFile文件指令 & 构建

    1.dockerfile指令格式 # Comment注释 INSTRUCTION argument指令名 + 参数 2.普通指令 1. FROM 已存在的镜像,基础镜像,第一条非注释指令 FROM & ...

  8. Java使用ResourceBundle类读取properties文件中文乱码的解决方案

    Java使用java.util.ResourceBundle类的方式来读取properties文件时不支持中文,要想支持中文必须将文件设置为ISO-8859-1编码格式,这对于开发工具默认为UTF-8 ...

  9. leetcode-19-merge

    88. Merge Sorted Array 解题思路: 需要注意,两个数组是排好序的,且nums1够大.所以从两个数组的尾端开始比较,大的那个放在nums1的尾部,并且放了之后就可以前进. 例如nu ...

  10. leetcode-14-basic-breadthFirstSearch

    BFS: breadth first search 107. Binary Tree Level Order Traversal II 解题思路: 本来我是用map<int,int>存所有 ...