codeforces 637B B. Chat Order(map,水题)
题目链接:
time limit per test
256 megabytes
standard input
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.
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.
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
4
alex
ivan
roman
ivan
ivan
roman
alex
8
alina
maria
ekaterina
darya
darya
ekaterina
maria
alina
alina
maria
ekaterina
darya
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
- alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
- ivan
- alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
- roman
- ivan
- 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:
- ivan
- roman
- alex
题意:按给的顺序联系他的朋友,把最后的列表打印出来;
思路:从后往前,没出现的输出,出现的就continue,记录是否出现过可以用map;
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+;
string str[N];
map<string,int>mp;
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
cin>>str[i];
}
for(int i=n-;i>=;i--)
{
if(!mp[str[i]])
{
cout<<str[i]<<"\n";
mp[str[i]]=;
}
}
return ;
}
codeforces 637B B. Chat Order(map,水题)的更多相关文章
- codeforces 677A A. Vanya and Fence(水题)
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Beta Round #37 A. Towers 水题
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...
- Codeforces - 1194B - Yet Another Crosses Problem - 水题
https://codeforc.es/contest/1194/problem/B 好像也没什么思维,就是一个水题,不过蛮有趣的.意思是找缺黑色最少的行列十字.用O(n)的空间预处理掉一维,然后用O ...
- codeforces 659C C. Tanya and Toys(水题+map)
题目链接: C. Tanya and Toys time limit per test 1 second memory limit per test 256 megabytes input stand ...
- codeforces Gym 100187H H. Mysterious Photos 水题
H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...
随机推荐
- 嵌入式开发之手机arm汇总---科普手机arm
http://www.leiphone.com/news/201406/1102-zzl-arm.html
- 打造自己的LINQ Provider(上):Expression Tree揭秘
概述 在.NET Framework 3.5中提供了LINQ 支持后,LINQ就以其强大而优雅的编程方式赢得了开发人员的喜爱,而各种LINQ Provider更是满天飞,如LINQ to NHiber ...
- 批处理--执行sql(mysql数据库)
@echo off rem test.sql文件 for %%i in (test.sql) do ( echo excute %%i mysql -u用户名 -p密码 -D数据库名 < %%i ...
- html5-框架网站
1.html5+:http://www.html5plus.org/ 2.hbuilder:http://www.dcloud.io/ 3.mui:http://dev.dcloud.net.cn/m ...
- pycharm的安装和破解
前提: 为了学习爬虫,单独下载了一个pycharm编辑器,所以就有了这篇文章,和PHPstorm的安装和破解及其类似, 如有想了解PHPstorm的安装破解可参考我的另一篇博文:http://www. ...
- hihocoder1260,1261 (HASH经典题)
这两题比赛做的时候各种卡,太久没有写过这种类型的题目了.各种细节想不清楚. 赛后看下网上大部分题解的代码,发现大部分都是直接用TRIE+暴力直接搞的--!,随便找了份代码发现有些数据这种做法是超时的, ...
- 【BZOJ3661】Hungry Rabbit 贪心
[BZOJ3661]Hungry Rabbit Description 可怕的洪水在夏天不期而至,兔子王国遭遇了前所未有的饥荒,它们不得不去外面的森林里寻找食物.为了简化起见,我们假设兔子王国中有n只 ...
- EasyNVR结合阿里云/腾讯云CDN实现微信/小程序直播的方案
背景需求: 许多客户有这样的需求:微信公众号做为平台来对摄像机进行直播:可以让用户随时随地打开公共号就可以观看:保证画面的流畅性:保证视频的并发访问量等. 问题分析: 虽然需求看似很简单,其实真正实现 ...
- java.util包下面的类---------01---示意图
一直在使用util包下面的这些类,甚至有些没用过的,想要都去认识认识他们!也许在未来的一天可以用到! 图太大不好截图!部分没有截全!
- NOIP考前划水
NOIP考前划水 君指先跃动の光は.私の一生不変の信仰に.唯私の超電磁砲永世生き! 要开始背配置了? 3行不谢. (setq c-default-style "awk") (glo ...