一二三四五 上山打老虎

天梯赛L1-020 帅到没朋友 (20 分)

链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805117167976448

反思:这个题中每个人的名称是五位的数字,但是用int类型存储的话只能得到15分,最后两个测试数据过不去;也就是测试数据中可能存在整数值相同但是字符串存储时不相同的情况;
对于题目中多位整数值作为标记的情况,最好用string存储

代码:

#include<bits/stdc++.h>

using namespace std;
unordered_map<string,bool>mp;
int main (){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int m;cin>>m;
        for(int j=0;j<m;j++){
            string str;
            cin>>str;
            if(m>1)mp[str]=true;
        }
    }
    cin>>n;
    bool f=false;
    for(int i=0;i<n;i++){
    string str;
        cin>>str;
        if(!mp[str]){
            mp[str]=true;
            if(f)cout<<" ";
            cout<<str;
            f=true;
        }
        }
    if(!f)cout<<"No one is handsome";
    return 0;
}
posted @ 2021-04-20 11:19  黒川川  阅读(151)  评论(0)    收藏  举报