PAT A1121 Damn Single (25 分)——set遍历
"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遍历的更多相关文章
- PTA PAT排名汇总(25 分)
PAT排名汇总(25 分) 计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科 ...
- PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)
1032 Sharing (25 分) To store English words, one method is to use linked lists and store a word let ...
- PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)
1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive int ...
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*
1029 Median (25 分) Given an increasing sequence S of N integers, the median is the number at the m ...
- PAT 1051 Pop Sequence (25 分)
返回 1051 Pop Sequence (25 分) Given a stack which can keep M numbers at most. Push N numbers in the ...
- PAT 甲级 1147 Heaps (30 分) (层序遍历,如何建树,后序输出,还有更简单的方法~)
1147 Heaps (30 分) In computer science, a heap is a specialized tree-based data structure that sati ...
- 【PAT】B1085 PAT单位排行(25 分)(c++实现)
终于做的有点眉目了,今天学习了一点stl的皮毛,解题瞬间变容易了 下边开始分析本题 这道题如果用纯c解决实在太麻烦,试了半天两个超时,果断放弃,还是用map方便: 我的方法与柳神的方法是有区别的,我只 ...
- PAT 07-图6 旅游规划 (25分)
有了一张自驾旅游路线图,你会知道城市间的高速公路长度.以及该公路要收取的过路费.现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径.如果有若干条路径都是最短的,那么需要输出最便 ...
随机推荐
- Django Rest Framework之解析器
基本代码结构 urls.py: from django.conf.urls import url, include from web.views.s5_parser import TestView u ...
- 【Mybatis】一对多实例
①创建数据库和表,数据库为mytest,表为teacher和student DROP TABLE IF EXISTS teacher; DROP TABLE IF EXISTS student; CR ...
- Spark 跑 java 示例代码
一.下载示例代码: git clone https://github.com/melphi/spark-examples.git 从示例代码中可以看到 pox中引入了 Spark开发所需要的依赖. 二 ...
- 【读书笔记】iOS-发布你的应用
一,添加图标 你的应用在iPhone主屏幕上的标准图标(Icon.png)是57像素*57像素的正方形,PNG格式,不能有透明效果或者图层,72DPI.除些之外,你还可以提供一个同样格式的114像素* ...
- 【读书笔记】iOS-iCloud文件备份
iOS应用在运行时经常要创建一些文件,不过这些文件要如何存放呢?有没有什么要求呢? 由于手机资源空间有限而且考虑到Apple推出的iCloud,我们确实要对创建出的文件按照作用的不同,分出几种类别出来 ...
- Code::Blocks + GDAL
[root@server20 ~]# yum install cmake cmake-gui [root@server20 ~]# yum install cairo-devel libcurl-de ...
- Network-Emulator Network-Emulator-Toolkit网络模拟器使用详细介绍
Network-Emulator-Toolkit网络模拟器使用详细介绍 by:授客 QQ:1033553122 原理介绍 图1 如上图,一个ADSL用户通过modem连接到网络,通过网络应用如IE,M ...
- (网页)angularjs中的interval定时执行功能(转)
转载博客园魔豆: 一个例子,用来显示当前实时时间,1秒钟刷新一次: <!DOCTYPE html> <html ng-app="myApp"> <he ...
- Django之验证
1. 滑动验证码补充说一下 极验科技:https://docs.geetest.com/install/deploy/server/python#下载SDK按照人家的实例操作即可 1.pip inst ...
- 【已解决】gradle project refresh failed:connection refused
git上clone一个Gradle项目,使用AS的gradle sync报错如下: Error:Connection refused (Connection refused) 原因:本地gradle版 ...