1121. Damn Single (25) map,set

来源:互联网 发布:西建大导师知乎 编辑:程序博客网 时间:2024/06/03 21:33

"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:
311111 2222233333 4444455555 66666755555 44444 10000 88888 22222 11111 23333
Sample Output:
510000 23333 44444 55555 88888

这题我记得当时考PAT乙的最后一题。。当时还不知道set,map。写的特别复杂。很多嵌套的循环(代码没保存,当时AC了,后面就没做)



用map建立关系,如果map【a】!=0,而且map[a]不存在set中,就是单身狗

或者说map【a】==0,肯定是单身狗

最后保存输出

#include<cstdio>#include<cmath>#include<algorithm>#include<iostream>#include<cstring>#include<queue>#include<vector>#include<set>#include<map>#include<stack>using namespace std;int main(){int n;cin>>n;map<int,int> m;for(int i=0;i<n;i++){    int a,b;    cin>>a>>b;    m[a+1]=b+1;    m[b+1]=a+1;}int k;cin>>k;set<int> s;for(int i=0;i<k;i++){int num;cin>>num;num++;s.insert(num);} int flag=1;int out[100001],cnt=0; for(set<int>::iterator it=s.begin();it!=s.end();it++){int num=*it;if(m[num]==0){ out[cnt++]=num-1;}else{    if(s.find(m[num])!=s.end()){    continue;}else{out[cnt++]=num-1;}}} cout<<cnt<<endl;for(int i=0;i<cnt;i++){if(i==0) printf("%05d",out[i]);else printf(" %05d",out[i]);}return 0;}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 酷狗音乐停止运行怎么办 米6蓝牙声音小怎么办 手里酷狗id丢了怎么办 连麦声音不好听怎么办 微信语音声音很难听怎么办 微信聊天语音没有声音怎么办 微信发语音声音不好听怎么办 微信语音说话不好听怎么办 微信字体变粗怎么办 笔记本无法识别usb设备怎么办 手机qq音乐闪退怎么办 qq音乐总是闪退怎么办 手机qq音乐闪退怎么办修复 苹果7p耳机漏音怎么办 akgn25耳机盖掉了怎么办 外汇平台跑路了怎么办 微云资料没了怎么办 酷狗k歌有杂音怎么办 手机k歌音质不好怎么办 酷狗让升级内测取消之后怎么办 苹果5s声音太小怎么办 苹果6p调均衡卡怎么办 忘记密码怎么办登录云教育 登录微信收不到验证码怎么办 红米手机黑白屏怎么办 手机登录不上电子邮件怎么办 如果台湾发生骚乱大陆怎么办 80端口被占用了怎么办? qq邮箱服务器密码忘记了怎么办 对方身份异常请验证怎么办 qq附近人屏蔽了怎么办 快递地址填错了怎么办 快递填错地址已经发货怎么办 淘宝受到卖家威胁怎么办 消费者被外卖商家威胁怎么办 拼多多商家打电话威胁怎么办 退款被拒商家还威胁怎么办? 打错电话给领导怎么办 领导送礼物给我怎么办 南瓜饼和面很稀怎么办 包饺子剩的肉馅怎么办