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 (<=50000),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 (<=10000) 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 22222 22222 33333 44444 55555 66666 7 55555 44444 10000 88888 22222 22222 23333 Sample Output:
1 #include<iostream> 2 #include<vector> 3 #include<set> 4 using namespace std; 5 int main(){ 6 vector<int> cp(100001,-1),present(100001),exist(100001,0); 7 set<int> ans; 8 int n,m,i,a,b,cnt=0; 9 cin>>n; 10 for(i=0; i<n; i++){ 11 scanf("%d%d",&a,&b); 12 cp[a] = b; 13 cp[b] = a; 14 } 15 cin>>m; 16 for(i=0; i<m; i++){ 17 scanf("%d",&present[i]); 18 exist[present[i]] = 1; 19 } 20 for(i=0; i<m; i++){ 21 if(!(cp[present[i]]!=-1 && exist[cp[present[i]]])){ 22 cnt++; 23 ans.insert(present[i]); 24 } 25 } 26 cout<<cnt<<endl; 27 for(auto it=ans.begin(); it!=ans.end(); it++){ 28 if(it==ans.begin()) printf("%05d",*it); 29 else printf(" %05d",*it); 30 } 31 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |