"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的更多相关文章

  1. PAT 1121 Damn Single[简单]

    1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...

  2. PAT甲级 1121. Damn Single (25)

    1121. Damn Single (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue "Dam ...

  3. 1121 Damn Single (25 分)

    1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...

  4. PTA 1121 Damn Single

    题目链接:1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who i ...

  5. PAT甲题题解-1121. Damn Single (25)-水题

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789787.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  6. PAT A1121 Damn Single (25 分)——set遍历

    "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...

  7. 1121 Damn Single

    题意: 给出n对情侣,然后给出聚会上的m个人,问这m个人中有几个人事落单的. 思路: 首先,开一个数组couple[]存储情侣间的映射关系:然后,用exist[]标记聚会上出现过的人:最后遍历0~N, ...

  8. 1121. Damn Single (25)

    "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...

  9. PAT 甲级真题题解(63-120)

    2019/4/3 1063 Set Similarity n个序列分别先放进集合里去重.在询问的时候,遍历A集合中每个数,判断下该数在B集合中是否存在,统计存在个数(分子),分母就是两个集合大小减去分 ...

随机推荐

  1. swift中使用GCDMulticastDelegate

    在开源库XMPPFramework中提供了一个GCDMulticastDelegate类,使用它可以为一个对象添加多个被委托的对象,以前用oc编写的工程引入了这个类,使用起来十分方便.最近由于换了工作 ...

  2. SQL Server2012 T-SQL基础教程--读书笔记(1-4章)

    SQL Server2012 T-SQL基础教程--读书笔记(1-4章) SqlServer T-SQL 示例数据库:点我 Chapter 01 T-SQL 查询和编程背景 1.3 创建表和定义数据的 ...

  3. IntelliJ IDEA 安装目录的核心文件讲解

    转自:https://blog.csdn.net/qq_35246620/article/details/61916751 首先,我们回顾一下前两篇关于 IntelliJ IDEA 的博文的内容: 在 ...

  4. HashMap1

    一.Java并发基础 当一个对象或变量可以被多个线程共享的时候,就有可能使得程序的逻辑出现问题. 在一个对象中有一个变量i=0,有两个线程A,B都想对i加1,这个时候便有问题显现出来,关键就是对i加1 ...

  5. 《Effective C++》笔记:III(转载)

    转自:http://www.cnblogs.com/destino74/p/3960802.html 条款5:Know what functions C++ silently writes and c ...

  6. bzoj 1029: [JSOI2007]建筑抢修【贪心+堆】

    第一想法是按照结束时间贪心,但是这样有反例 所以先按照t贪心,能选则选,把选的楼的持续时间放进大根堆里,当当前的楼不能选的时候如果当前的持续时间比大根堆里最大的要小,就用这个替换最大,这样总数不变但是 ...

  7. 指向“”的 script 加载失败

    今天遇到了一个非常奇怪的问题:在某个同时的电脑上,所有浏览器无法打开某个页面,F12查看控制台,发现有一个黄色的 指向“xxxx.js”的 <script> 加载失败 的提示.该外部js文 ...

  8. http升级https(转)

    让你的网站免费支持 HTTPS 及 Nginx 平滑升级 为什么要使用 HTTPS ? 首先来说一下 HTTP 与 HTTPS 协议的区别吧,他们的根本区别就是 HTTPS 在 HTTP 协议的基础上 ...

  9. TFS修改了工作区

    计算机修改名字后,更换了TFS工作区,但原工作区的有些文件忘记签入: 解决方案: 删除原工作区即可,实现:到TFS工作区 - “管理工作区”,选中“显示远程工作区”,找到原工作区,删除即可.

  10. SQL server 查询语句 练习题

    用SQL语句创建四个表: create database tongjigouse tongjigocreate table student(Sno varchar(20) not null prima ...