1121 Damn Single (25 分)

时间:2024-11-22 14:35:37
1121 Damn Single (25 分)

"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are supposed to find those who are alone in a big party, so they can be taken care of.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤ 50,000), the total number of couples. Then N lines of the couples follow, each gives a couple of ID's which are 5-digit numbers (i.e. from 00000 to 99999). After the list of couples, there is a positive integer M (≤ 10,000) followed by M ID's of the party guests. The numbers are separated by spaces. It is guaranteed that nobody is having bigamous marriage (重婚) or dangling with more than one companion.

Output Specification:

First print in a line the total number of lonely guests. Then in the next line, print their ID's in increasing order. The numbers must be separated by exactly 1 space, and there must be no extra space at the end of the line.

Sample Input:

3
11111 22222
33333 44444
55555 66666
7
55555 44444 10000 88888 22222 11111 23333

Sample Output:

5
10000 23333 44444 55555 88888

题意:找出谁是“单身狗”。。。先输入各对CP,然后再输入参加party的人员,统计输入的这些人里哪些是没有CP一起来的,升序输出。

分析:水题。。我思路是用一个数组couple,初始化为-1(因为人的编号为00000-99999),作用是来存储某人的CP,如11111的CP是22222,那么couple[11111]=22222,couple[22222]=11111。最后因为要格式输出,不知道迭代器怎么格式输出。。就先把结果存到了vector中,具体见代码
 /**
 * Copyright(c)
 * All rights reserved.
 * Author : Mered1th
 * Date : 2019-02-27-21.51.47
 * Description : A1121
 */
 #include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<cmath>
 #include<algorithm>
 #include<string>
 #include<unordered_set>
 #include<map>
 #include<vector>
 #include<set>
 using namespace std;
 ;
 };
 int main(){
 #ifdef ONLINE_JUDGE
 #else
     freopen("1.txt", "r", stdin);
 #endif
     int n,m,u,v,t;
     scanf("%d",&n);
     ;i<n;i++){
         scanf("%d%d",&u,&v);
         couple[u]=v;
         couple[v]=u;
     }
     scanf("%d",&m);
     vector<int> tem;
     ;i<m;i++){
         scanf("%d",&t);
         tem.push_back(t);
     }
     set<int> ans;
     ;i<m;i++){
         int coup=couple[tem[i]];
         ) ans.insert(tem[i]);
         else{
             if(find(tem.begin(),tem.end(),coup)==tem.end()){
                 ans.insert(tem[i]);
             }
         }
     }
     cout<<ans.size()<<endl;
     vector<int> res;
     for(auto it=ans.begin();it!=ans.end();it++){
         res.push_back(*it);
     }
     ;i<res.size();i++){
         printf("%05d",res[i]);
         ) printf(" ");
     }
     ;
 }