PAT 1121 Damn Single
"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
#include<iostream> //水题
#include<vector>
#include<algorithm>
using namespace std;
int main(){
vector<int> couples(100000, 0), visited(100000, 0), single, ans;
int n;
cin>>n;
for(int i=0; i<n; i++){
int p, q;
cin>>p>>q;
couples[p]=q;
couples[q]=p;
}
cin>>n;
for(int i=0; i<n; i++){
int t;
cin>>t;
visited[t]=1;
single.push_back(t);
}
for(int i=0; i<n; i++)
if(visited[couples[single[i]]]==0)
ans.push_back(single[i]);
sort(ans.begin(), ans.end());
cout<<ans.size()<<endl;
for(int i=0; i<ans.size(); i++)
i==0?printf("%05d", ans[i]):printf(" %05d", ans[i]);
return 0;
}
PAT 1121 Damn Single的更多相关文章
- PAT 1121 Damn Single[简单]
1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...
- PAT甲级 1121. Damn Single (25)
1121. Damn Single (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue "Dam ...
- 1121 Damn Single (25 分)
1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...
- PTA 1121 Damn Single
题目链接:1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who i ...
- PAT甲题题解-1121. Damn Single (25)-水题
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789787.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- PAT A1121 Damn Single (25 分)——set遍历
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...
- 1121 Damn Single
题意: 给出n对情侣,然后给出聚会上的m个人,问这m个人中有几个人事落单的. 思路: 首先,开一个数组couple[]存储情侣间的映射关系:然后,用exist[]标记聚会上出现过的人:最后遍历0~N, ...
- 1121. Damn Single (25)
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...
- PAT 甲级真题题解(63-120)
2019/4/3 1063 Set Similarity n个序列分别先放进集合里去重.在询问的时候,遍历A集合中每个数,判断下该数在B集合中是否存在,统计存在个数(分子),分母就是两个集合大小减去分 ...
随机推荐
- gitlab https
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md#using-https https:// ...
- 准确率,精确率,召回率,F-measure 之间的关系
总结:(图上 R的计算的分母应该是 :40+10 )(笔误) 模型条件放宽,负类被误判为正类的可能性就变大(即FP变大)精确率和准确率会受影响(变小) 模型条件变严格,正类有可能被误判为负类(即FN变 ...
- PCB拼板之多款矩形排样算法实现--学习
参考资料:<一种新型pcb合拼求解过程> 拼版合拼问题描述和求解过程 合拼问题描述 Pcb合拼问题是通过二维矩形组合排样而演化与扩展而形成的一种新拼版问题,把每个零件都看成一个规则的矩形进 ...
- Entityframework Code First 系列
总篇, 下面会添加每个小篇的链接. 目录如下: 项目搭建 ……
- win7升级到win10不能上网解决方法
不要相信360的网络诊断了,都是坑货,没有什么用.下面的方法亲测有效.如君不行,那估计是win10版本不一样,原因另寻. 1.以管理员身份运行CMD,输入netsh winsock reset. 2. ...
- Spring: (一) -- 春雨润物之 核心IOC
作为一个Java人,想必都或多或少的了解过Spring.对于其优势也能道个一二,诸如方便解耦.支持AOP编程.支持声明式事务.方便测试等等.Spring也不仅仅局限于服务器端开发,它可以做非常多的事情 ...
- C语言用指针输出数组里的值
因为*(arr)是指arr数组内存编号所对应的首地址的值,即arr[0]的值.所以用*(arr+i)可以实现遍历整个数组.
- 对于es6的小小理解之generator函数
相信很多学js的人都看过es6,我也是最近才看的es6标准.下面我来说一下我对es6笼统的看法,如有不对欢迎评论交流. js有很长很长的历史,大家应该都有了解过.es6是15年发布的版本,由TC39主 ...
- python 关于一个懒惰和非懒惰的
>>> pa = re.compile(r'<.*>') >>> result = pa.findall('<H1>title</H1 ...
- oracle创建临时表空间、用户表空间、创建用户关联表空间、授权等
1.创建临时表空间 CREATE TEMPORARY TABLESPACE test_temp TEMPFILE 'C:\oracle\product\10.1.0\oradata\orcl\test ...