• L1-020. 帅到没朋友


    https://www.patest.cn/contests/gplt/L1-020

    L1-020. 帅到没朋友

    时间限制
    200 ms
    内存限制
    65536 kB
    代码长度限制
    8000 B
    判题程序
    Standard
    作者
    陈越

    当芸芸众生忙着在朋友圈中发照片的时候,总有一些人因为太帅而没有朋友。本题就要求你找出那些帅到没有朋友的人。

    输入格式:

    输入第一行给出一个正整数N(<=100),是已知朋友圈的个数;随后N行,每行首先给出一个正整数K(<=1000),为朋友圈中的人数,然后列出一个朋友圈内的所有人——为方便起见,每人对应一个ID号,为5位数字(从00000到99999),ID间以空格分隔;之后给出一个正整数M(<=10000),为待查询的人数;随后一行中列出M个待查询的ID,以空格分隔。

    注意:没有朋友的人可以是根本没安装“朋友圈”,也可以是只有自己一个人在朋友圈的人。虽然有个别自恋狂会自己把自己反复加进朋友圈,但题目保证所有K超过1的朋友圈里都至少有2个不同的人。

    输出格式:

    按输入的顺序输出那些帅到没朋友的人。ID间用1个空格分隔,行的首尾不得有多余空格。如果没有人太帅,则输出“No one is handsome”。

    注意:同一个人可以被查询多次,但只输出一次。

    输入样例1:
    3
    3 11111 22222 55555
    2 33333 44444
    4 55555 66666 99999 77777
    8
    55555 44444 10000 88888 22222 11111 23333 88888
    
    输出样例1:
    10000 88888 23333
    
    输入样例2:
    3
    3 11111 22222 55555
    2 33333 44444
    4 55555 66666 99999 77777
    4
    55555 44444 22222 11111
    
    输出样例2:
    No one is handsome


    总结:
    每个人的思路不同,方法不同,可能犯的错也不同。
    像这道题,后两个测试点一直wrong answer,原来,ID我用的int,题目固定5位,输出应注意补0

    #include "cstdio"
    #include "map"
    using namespace std;
    map<int,int> fri;  ///有朋友的所有人
    map<int,int> temp_mul;///输出过的所有人
    int x_x[1010];///暂存ID
    int main()
    {
        int n,t;
        while(~scanf("%d",&n)&&n)
        {
            fri.clear();
            temp_mul.clear();
    
            int x,k,flag1=0,def;
            for(int i=0;i<n;i++){///注意输入该如何存储
                scanf("%d",&k);
                flag1=0;
                for(int j=0;j<k;j++){
                    scanf("%d",&x);
                    if(k>1){
                        x_x[j]=x;
                        if(j==0)
                            def=x;
                        else{
                            if(def!=x)flag1=1;
                        }
                    }
                }
                if(flag1){
                   for(int j=0;j<k;j++){
                         fri[x_x[j]]++;
                   }
                }
            }
            int check=0,flag=1,c=0;
            scanf("%d",&check);
            for(int i=0;i<check;i++){
                scanf("%d",&x);
                if(fri.find(x)==fri.end()&&temp_mul.find(x)==temp_mul.end())
                {
                    if(flag==1)
                        printf("%05d",x),flag++;
                    else
                        printf(" %05d",x);
                    temp_mul[x]++;
                    c++;
                }
            }
            if(c==0)
                printf("No one is handsome");
            printf("
    ");
        }
        return 0;
    }
    #include <iostream>
    #include <set>
    using namespace std;
    int main() {
        int a, b, c;
        cin >> a;
        set<string> s, ans;
        string str;
        for(int i = 0; i < a; i++) {
            cin >> b;
            if(b >= 2) {
                for(int j = 0; j < b; j++) {
                    cin >> str;
                    s.insert(str);
                }
            } else {
                cin >> str;
            }
        }
        cin >> c;
        int flag = 0;
        for(int i = 0; i < c; i++) {
            cin >> str;
            if(s.find(str) == s.end() && ans.find(str) == ans.end()) {
                ans.insert(str);
                if(flag == 1)
                    cout << " ";
                cout << str;
                flag = 1;
            }
        }
        if(flag == 0)
            cout << "No one is handsome";
        return 0;
    }
  • 相关阅读:
    【USACO2017JAN】 Promotion Counting
    【POJ 3468】 A Simple Problem with Integers
    【HDU 1754】 I Hate It
    【Codeforces 20C】 Dijkstra?
    【POJ 2407】 Relatives
    BZOJ5249 九省联考2018IIIDX(线段树+贪心)
    BZOJ5251 八省联考2018劈配(网络流)
    BZOJ4200 NOI2015小园丁与老司机(动态规划+上下界网络流)
    BZOJ3876 AHOI/JSOI2014支线剧情(上下界网络流)
    LOJ117 有源汇有上下界最小流(上下界网络流)
  • 原文地址:https://www.cnblogs.com/kimsimple/p/6574556.html
Copyright © 2020-2023  润新知