PAT甲级——A1121 Damn Single【25】
"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
使用couple记录是否有配偶
10000 23333 44444 55555 88888
使用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】的更多相关文章
- PAT甲级 1121. Damn Single (25)
1121. Damn Single (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue "Dam ...
- 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)
题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...
- PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)
1024 Palindromic Number (25 分) A number that will be the same when it is written forwards or backw ...
- PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following r ...
- PAT甲级 1122. Hamiltonian Cycle (25)
1122. Hamiltonian Cycle (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...
- PAT甲级 1126. Eulerian Path (25)
1126. Eulerian Path (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue In grap ...
- PAT甲级 1130. Infix Expression (25)
1130. Infix Expression (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Give ...
- PAT甲级 1129. Recommendation System (25)
1129. Recommendation System (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- PAT 甲级 1020 Tree Traversals (25分)(后序中序链表建树,求层序)***重点复习
1020 Tree Traversals (25分) Suppose that all the keys in a binary tree are distinct positive intege ...
随机推荐
- Job 和 Cronjob 的使用
Job负责处理任务,即仅执行一次的任务,它保证批处理任务的一个或多个Pod成功结束.而CronJob则就是在Job上加上了时间调度. Job 我们用Job这个资源对象来创建一个任务,我们定一个Job来 ...
- react 组件的构造函数
constructor 函数时组件最先执行的函数 class childen extends react.Component{ constructor(props){ super(props); th ...
- 安装和使用pyspider框架时遇到的问题
安装pyspider, 直接cmd中输入 pip install pyspider, 而后提示报错 从网上找到解决方法,pycurl需要根据python版本采用wheel方法安装. 下载链接为http ...
- 使用babel转码器,让浏览器支持es6语法
ECMAScript 6.0(以下简称 ES6)是 JavaScript 语言的下一代标准,可是很多浏览器并不支持es6语法,所以我们需要一个转码工具, 把es6的语法转换成浏览器支持的javascr ...
- Java——对象
1.2对象 1.2.1 对象的创建和使用 ①使用new + 构造器创建一个新的对象: ②使用“对象名.对象成员”的方式访问对象成员(包括属性和方法). public class Animal { pu ...
- NX二次开发-获取UG界面窗口句柄UF_UI_get_default_parent
1 extern "C" DllExport void ufusr(char *param, int *retcod, int param_len) 2 { 3 4 if (UF_ ...
- Android中滑屏实现----触摸滑屏以及Scroller类详解 .
转:http://blog.csdn.net/qinjuning/article/details/7419207 知识点一: 关于scrollTo()和scrollBy()以及偏移坐标的设置/取值问 ...
- spring boot 重复提交
package com.future.interceptor; import javax.servlet.http.HttpServletRequest; import org.aspectj.lan ...
- Eclipse+Maven创建webapp项目 及部署在tomcat上
1.开启eclipse,右键new——>other,如下图找到maven project 2.选择maven project,显示创建maven项目的窗口,勾选如图所示,Create a sim ...
- python+tushare获取A股所有股票代码和名称列表
接口:stock_basic 描述:获取基础信息数据,包括股票代码.名称.上市日期.退市日期等 注:tushare模块下载和安装教程,请查阅我之前的文章 输入参数 名称 | 类型 ...