"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
使用couple记录是否有配偶
使用flag标记是否配偶到场
注意:最后不要输出换行,不然一旦没有输出,那么就有两个换行了!
 #include <iostream>
#include <set>
using namespace std;
int main()
{
int n, m, boy, girl, id;
int couple[], flag[];
set<int>guests, res;
cin >> n;
fill(couple, couple + , -);
fill(flag, flag + , );
while (n--)
{
cin >> boy >> girl;
couple[boy] = girl;
couple[girl] = boy;
}
cin >> m;
while (m--)
{
cin >> id;
guests.insert(id);
if (couple[id] == -)
continue;
else if (flag[id] == )//对偶没有来
{
flag[id] = ;
flag[couple[id]] = ;
}
else if (flag[id] == )//对偶来了
{
flag[id] = -;
flag[couple[id]] = -;
}
}
for (auto a : guests)
{
if (flag[a] != -)
res.insert(a);
}
cout << res.size() << endl;
for (auto a : res)
printf("%s%05d", (a == *(res.begin()) ? "" : " "), a);
return ;
}

PAT甲级——A1121 Damn Single【25】的更多相关文章

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

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

  2. 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

    题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...

  3. PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)

    1024 Palindromic Number (25 分)   A number that will be the same when it is written forwards or backw ...

  4. PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

    1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following r ...

  5. PAT甲级 1122. Hamiltonian Cycle (25)

    1122. Hamiltonian Cycle (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...

  6. PAT甲级 1126. Eulerian Path (25)

    1126. Eulerian Path (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue In grap ...

  7. PAT甲级 1130. Infix Expression (25)

    1130. Infix Expression (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Give ...

  8. PAT甲级 1129. Recommendation System (25)

    1129. Recommendation System (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  9. PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习

    1020 Tree Traversals (25分)   Suppose that all the keys in a binary tree are distinct positive intege ...

随机推荐

  1. Shell [[]]详解:检测某个条件是否成立

    [[ ]]是 Shell 内置关键字,它和 test 命令类似,也用来检测某个条件是否成立. test 能做到的,[[ ]] 也能做到,而且 [[ ]] 做的更好:test 做不到的,[[ ]] 还能 ...

  2. bean创建

    看<spring源码解析>的笔记 1.通过@Bean创建bean,类上需要添加@Configuration @Configuration public class MainConfig { ...

  3. 28. string类中方法练习

    1. 自己写trim方法 public class Demo3 { public static void main(String[] args) { System.out.println(myTrim ...

  4. css reset初始化样式

    原文:https://www.cnblogs.com/caojiayan/p/6343917.html /* CSS Document */ html, body, div, span, object ...

  5. 好久不见的博客咯!——没有可持久化的可持久化treap

    每每想要去了解可持久化treap这个好写好调的东东,然后就发现网上只有一个人的——SymenYang的!在此我必须得把他批判一番——写方法不贴代码是什么心态!而且写出来的是有问题的呀!害人不浅! 好吧 ...

  6. usb基础知识以及枚举过程介绍

    一个USB设备有一个设备描述符,设备描述符里面决定了该设备有多少种配置,每种配置描述符对应着配置描述符:而在配置描述符中又定义了该配置里面有多少个接口,每个接口有对应的接口描述符:在接口描述符里面又定 ...

  7. CSS3:CSS3 渐变(Gradients)

    ylbtech-CSS3:CSS3 渐变(Gradients) 1.返回顶部 1. CSS3 渐变(Gradients) CSS3 渐变(gradients)可以让你在两个或多个指定的颜色之间显示平稳 ...

  8. LeetCode 1041. Robot Bounded In Circle (困于环中的机器人)

    题目标签:Math 题目让我们判断机器人是否是一直在走一个圈. 当我们把 instructions 走完一遍时候: 1. 如果机器人回到了原点,那么它是在走一个圈. 2. 如果机器人的方向没有改变,那 ...

  9. Python骚操作(一)

    1. 交换变量值 2. 将列表中所有元素组合成字符串 3. 查找列表中频率最高的值 4. 检查连个字符串是不是由相同字母不同顺序组成 5. 反转字符串 6. 反转列表 7. 转置二维数组 8. 链式比 ...

  10. C++之变量

    变量 **作用**:给一段指定的内存空间起名,方便操作这段内存 **语法**:数据类型 变量名 = 初始值; 语法:数据类型  变量名 = 初始值;   记得加英文分号结束语句 > 注意:C++ ...