• VK Cup 2016


    B. Chat Order

    题目连接:

    http://www.codeforces.com/contest/637/problem/B

    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

    4
    alex
    ivan
    roman
    ivan

    Sample Output

    ivan
    roman
    alex

    Hint

    题意

    有一个人,有一个队列。

    然后现在依次插入n个单词,如果这个单词已经在队列中了,那就把这个单词从原来位置扔到队列首。

    否则就把这个单词扔到队首。

    问你最后这个队列长啥样。

    题解:

    其实倒着输出就好了,然后开个map记录一下vis就行了。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 200005;
    string s[maxn];
    map<string,int>vis;
    int main()
    {
        int n;scanf("%d",&n);
        for(int i=1;i<=n;i++)
            cin>>s[i];
        for(int i=n;i;i--)
        {
            if(vis[s[i]])continue;
            cout<<s[i]<<endl;
            vis[s[i]]=1;
        }
    }
  • 相关阅读:
    华硕笔记本无法U盘启动,快捷键识别不了
    怎么将uefi改成legacy启动|BIOS设置legacy引导模式的方法
    [CDLinux]制作U盘CDLinux系统启动盘
    重装系统时,将MBR分区转为GPT 分区
    5-Comments
    4-HTML Computer Code Elements
    3-html 缩写-地址-文字方向-引用块-题注的格式
    2-HTML Text Formatting Elements
    1-HTML Attributes
    LabVIEW--为设备添加配置文件.ini
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5289818.html
Copyright © 2020-2023  润新知