"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 <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
using namespace std;
const int maxn=;
int couple[maxn]={};
vector<int> v;
int peop[maxn]={};
int n;
int main(){
scanf("%d",&n);
for(int i=;i<n;i++){
int cp,cp2;
scanf("%d %d",&cp,&cp2);
couple[cp]=cp2;
couple[cp2]=cp;
}
scanf("%d",&n);
for(int i=;i<n;i++){
int p;
scanf("%d",&p);
peop[p]=;
v.push_back(p);
}
for(int i=;i<n;i++){
if(peop[v[i]]==){
if(peop[couple[v[i]]]== && couple[couple[v[i]]]==v[i]){
peop[v[i]]=;
peop[couple[v[i]]]=;
}
}
}
int cnt=;
for(int i=;i<n;i++){
if(peop[v[i]]==){
cnt++;
}
}
printf("%d\n",cnt);
int num=;
sort(v.begin(),v.end());
for(int i=;i<n;i++){
if(peop[v[i]]==){
printf("%05d",v[i]);
num++;
if(num!=cnt)printf(" ");
}
}
}

注意点:一开始想用set和map,发现map其实就是一个大数组,还不如直接开个大数组。一开始题目理解错了,以为只要找给的人里是单身狗的就行,结果是有对象的对象没来也算单身,行吧

PAT A1121 Damn Single (25 分)——set遍历的更多相关文章

  1. PTA PAT排名汇总(25 分)

    PAT排名汇总(25 分) 计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科 ...

  2. PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)

    1032 Sharing (25 分)   To store English words, one method is to use linked lists and store a word let ...

  3. PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)

    1078 Hashing (25 分)   The task of this problem is simple: insert a sequence of distinct positive int ...

  4. PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)

    1070 Mooncake (25 分)   Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...

  5. PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*

    1029 Median (25 分)   Given an increasing sequence S of N integers, the median is the number at the m ...

  6. PAT 1051 Pop Sequence (25 分)

    返回 1051 Pop Sequence (25 分)   Given a stack which can keep M numbers at most. Push N numbers in the ...

  7. PAT 甲级 1147 Heaps (30 分) (层序遍历,如何建树,后序输出,还有更简单的方法~)

    1147 Heaps (30 分)   In computer science, a heap is a specialized tree-based data structure that sati ...

  8. 【PAT】B1085 PAT单位排行(25 分)(c++实现)

    终于做的有点眉目了,今天学习了一点stl的皮毛,解题瞬间变容易了 下边开始分析本题 这道题如果用纯c解决实在太麻烦,试了半天两个超时,果断放弃,还是用map方便: 我的方法与柳神的方法是有区别的,我只 ...

  9. PAT 07-图6 旅游规划 (25分)

    有了一张自驾旅游路线图,你会知道城市间的高速公路长度.以及该公路要收取的过路费.现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径.如果有若干条路径都是最短的,那么需要输出最便 ...

随机推荐

  1. 【IDEA&&Eclipse】4、IntelliJ IDEA上操作GitHub

    IntelliJ IDEA集成了对GitHub的支持,使上传代码到GitHub和从GitHub下载代码更加方便快捷. 1. 分享代码到GitHub 首先需要在IntelliJ配置Git,如果没有正确配 ...

  2. 【20】策略者模式(Strategy Pattern)

    一.引言 本文要介绍的策略模式也就是对策略进行抽象,策略的意思就是方法,所以也就是对方法的抽象,下面具体分享下我对策略模式的理解. 二.策略者模式介绍 2.1 策略模式的定义 在现实生活中,策略模式的 ...

  3. SQL Server 基本SELECT语句

    1.SELECT 和 FROM 语句 SELECT表示执行的是查询,接着需要更知道从哪边查询数据,FROM就是限制读取的数据在哪一个表或哪几个表中,这样就构成了一个基本语句. SELECT * FRO ...

  4. 关于Ajax的get与post浅分析,同步请求与异步请求,跨域请求;

    Ajax局部异步刷新全称ASynchronous JavaScript And XML.使用Javascript代码获取服务器的数据,Ajax当中有两个请求方法,一个是get方法,一个是post请求方 ...

  5. html 字符串 生成 pdf 完美解决中文不显示

    //maven <dependency> <groupId>com.itextpdf</groupId> <artifactId>itextpdf< ...

  6. UED与UCD

    UED User Experience Design(用户体验设计),简称UED.UED是以用户为中心的一种设计手段,以用户需求为目标而进行的设计.设计过程注重以用户为中心,用户体验的概念从开发的最早 ...

  7. “京东金融”主页效果 RecyclerView联动

    先上效果图吧: 第一个想到的实现方式是上面使用horizontalScrollview,下面使用Viewpager,经过尝试之后发现二者API有限,不能达到理想效果.几经折腾,最后上下都使用了自定义的 ...

  8. Expo大作战(二十九)--expo sdk api之registerRootComponent(注册跟组件),ScreenOrientation(屏幕切换),SecureStore,

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...

  9. Python创建空DataFrame及添加行数据

    # 创建空DataFrame df = pd.DataFrame(columns = ['YJML','EJML','SJML','WZLB','GGXHPZ','CGMS']) # 插入数据(忽略索 ...

  10. 分享一下我研究SQLSERVER以来收集的笔记

    分享一下我研究SQLSERVER以来收集的笔记 前言 为什麽分享??因为像现在网上很多人攻城师那样,转行去卖水果,卖早餐,总有一日我也会离开这个行业的 由于本人不是在大公司上班工资很低,我希望有一天存 ...