zoukankan      html  css  js  c++  java
  • L1-020 帅到没朋友 (20分)

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

    输入格式:

    输入第一行给出一个正整数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
    

    代码:

    利用set容器的特性即可,同时标记一下空格输出即可

    // Author : RioTian
    // Time : 20/10/28
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    int n, m, a, b;
    set<string> s, ans;
    string str;
    int main() {
        // freopen("in.txt", "r", stdin);
        ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
        cin >> n;
        for (int i = 0; i < n; ++i) {
            cin >> b;
            if (b >= 2)
                for (int j = 0; j < b; ++j) cin >> str, s.insert(str);
            else
                cin >> str;
        }
        cin >> m;
        bool flag = false;
        for (int i = 0; i < m; ++i) {
            cin >> str;
            if (s.find(str) == s.end() and ans.find(str) == ans.end()) {
                ans.insert(str);
                if (flag) cout << " ";
                cout << str, flag = true;
            }
        }
        if (!flag) cout << "No one is handsome";
    }
    

    The desire of his soul is the prophecy of his fate
    你灵魂的欲望,是你命运的先知。

  • 相关阅读:
    frp服务器搭建
    vue cli工具UI,AXIOS开发流程
    vue-cli 3.0之跨域请求代理配置及axios路径配置
    利用CSS、JavaScript及Ajax实现图片预加载的三大方法
    Preload图片预加载(jQuery插件)
    Unigui Basic jQuery学习
    emqtt 系统主题
    变量命名法
    Excel-VBA常用对象(Application、Workbook、Worksheet、Range)
    SqlServer对select * from (select *from table) 支持
  • 原文地址:https://www.cnblogs.com/RioTian/p/13893350.html
Copyright © 2011-2022 走看看