"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. python-面向对象-01课堂笔记

    面向对象 ''''1.面向过程编程   核心是"过程"二字,过程指的是解决问题的步骤,即先干什么再干什么   基于该思想编写程序就好比在编写一条流水线,是一种机械式的思维方式​   ...

  2. leetcood学习笔记-167-两数之和 II - 输入有序数组

    题目描述: 第一次提交: class Solution(object): def twoSum(self, numbers, target): """ :type num ...

  3. JAVA javah

    { 用法:  javah [options] <classes>其中, [options] 包括:  -o <file>                输出文件 (只能使用 - ...

  4. Javascript下拉刷新

    Html相关代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  5. NX二次开发-UFUN输入表达式名称,获取它的名称和值UF_MODL_ask_exp

    NX9+VS2012 #include <uf.h> #include <uf_modl.h> UF_initialize(); //创建一个新的表达式,有TAG tag_t ...

  6. string的find("")

    ); string strleft; int FindMin = TempRangeData1.find(("_")); ) { strleft = (TempRangeData1 ...

  7. centos7.5下coredns+etcd搭建DNS服务器

    coredns简介 安装etcd 安装coredns 设置域名解析 A记录 AAAA记录 CNAME记录 SRV记录 TXT记录 coredns简介 CoreDNS是一个DNS服务器,和Caddy S ...

  8. gvim 安装YouCompleteMe插件

    可以参考:YouCompleteMe#full-installation-guide 可以直接下载: http://pan.baidu.com/s/1dDIq2Al 密码: si5q 确保vim支持p ...

  9. 利用DOM节点找对象和直接在标签属性中调函数传值this的书写区别

    同样的功能,不同的书写格式. 1.个人觉得比较繁琐的写法,但是比较常见,特别是在大项目的时候常用的就是这种方法: <div id="mouse" onmouseover=&q ...

  10. NPE问题

    “防止 NPE,是程序员的基本修养.”NPE(Null Pointer Exception) 参考: https://www.jianshu.com/p/9915f2e34a13