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分)
有了一张自驾旅游路线图,你会知道城市间的高速公路长度.以及该公路要收取的过路费.现在需要你写一个程序,帮助前来咨询的游客找一条出发地和目的地之间的最短路径.如果有若干条路径都是最短的,那么需要输出最便 ...
随机推荐
- 【Java并发编程】13、forkjoin
http://www.infoq.com/cn/articles/fork-join-introduction http://www.importnew.com/14506.html Java7中的F ...
- Java开发中json使用,各对象与json相互转换
Json:一种网络通信使用的数据格式,因为便于解析,比较流行,对象可以转为json,同样json也可以转对象. 下面介绍下Json工具的简单使用(fastjson && jackson ...
- Vue 系列之 基础入门
背景叙述 渐进式 JavaScript 框架 易用:已经会了 HTML.CSS.JavaScript?即刻阅读指南开始构建应用! 灵活:不断繁荣的生态系统,可以在一个库和一套完整框架之间自如伸缩. 高 ...
- 复盘价值1000万的腾讯云硬盘固件"BUG"
摘要: 除了吃瓜,还是得吸取教训啊同学们! 这次,我从纯技术角度分析腾讯云与前沿数控的磁盘数据丢失事件,不站队. 硬盘门 这里说的硬盘门不是10年前陈老师的那一次,而聊的是最近"腾讯云&qu ...
- CSS--使用伪选择器制作箭头图标
// 使用Transform的属性,组合translate(位移)和rotate(旋转),将生成的小矩形组合成各种箭头样式: HTML <section class="main&quo ...
- js之返回网页顶部
目标效果:浏览网页过程中,滑动滚轮,显示返回顶部按钮,点击返回顶部后,返回网页顶端. 代码如下: <!DOCTYPE html> <html lang="en"& ...
- 2018-01-15 History in Threads: 火狐插件实现浏览历史按主题显示(树)
History in Threads似乎是唯一一个业余项目里有确认用户的. 大部分JavaScript源码(300+行)也用了中文命名. 插件功能很简单, 就是根据网页点击顺序生成树, 每个树可以认为 ...
- 【代码笔记】Web-HTML-表单
一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- python自动化开发-6-常用模块-续
python的常用模块(续) shelve模块:是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式. configparser模块:对配置文件进行 ...
- Salesforce的公式和验证规则
公式 在Salesforce中,有些功能不需要从数据库中直接读取的数据,而是基于这些数据之间的关系来做出判断.这种情况下就要用到"公式"功能. 公式的概念和Excel中的公式类似, ...