牛客--2019网易游戏(互娱)--会话列表

题目描述:
小云正在参与开发一个即时聊天工具,他负责其中的会话列表部分。

会话列表为显示为一个从上到下的多行控件,其中每一行表示一个会话,每一个会话都可以以一个唯一正整数id表示。

当用户在一个会话中发送或接收信息时,如果该会话已经在会话列表中,则会从原来的位置移到列表的最上方;如果没有在会话列表中,则在会话列表最上方插入该会话。

小云在现在要做的工作是测试,他会先把会话列表清空等待接收信息。当接收完大量来自不同会话的信息后,就输出当前的会话列表,以检查其中是否有bug。
输入描述:
对于每一组数据,输出一行,按会话列表从上到下的顺序,输出会话id。
相邻的会话id以一个空格分隔,行末没有空格。
输出描述:
只能输出1, -1,或0
输入:
3
5
1 2 3 4 5
6
1 100 1000 1000 100 1
7
1 6 3 3 1 8 1
输出:
5 4 3 2 1
1 100 1000
1 8 3 6
题意:
题目描述
题解
乱搞一下
代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<set>
#include<map>
using namespace std;

const int maxn = 200 + 5;
int a[maxn];

int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        map<int,int> mp;
        scanf("%d",&n);
        for(int i = 1; i <= n; i ++) scanf("%d",&a[i]);
        for(int i = n; i >= 1; i --){
            if(mp[a[i]] == 0){
                printf("%d ",a[i]);
                mp[a[i]] ++;
            }
        }
        printf("\n");
    }
    return 0;
}

发布了228 篇原创文章 · 获赞 1 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/Ypopstar/article/details/105126972