A1121. Damn Single
"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 (<=50000), 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 (<=10000) 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<cstdio>
#include<iostream>
#include<vector>
using namespace std;
int couple[], guest[] = {,};
int main(){
int N, M;
fill(couple, couple + , -);
scanf("%d", &N);
for(int i = ; i < N; i++){
int cp1,cp2;
scanf("%d%d", &cp1, &cp2);
couple[cp1] = cp2;
couple[cp2] = cp1;
}
scanf("%d", &M);
for(int i = ; i < M; i++){
int cp;
scanf("%d", &cp);
guest[cp] = ;
}
vector<int> ans;
for(int i = ; i < ; i++){
if(guest[i] == && (couple[i] == - || guest[couple[i]] == ))
ans.push_back(i);
}
printf("%d\n", ans.size());
for(int i = ; i < ans.size(); i++){
if(i == ans.size() - )
printf("%05d", ans[i]);
else printf("%05d ", ans[i]);
}
cin >> N;
return ;
}
A1121. Damn Single的更多相关文章
- PAT A1121 Damn Single (25 分)——set遍历
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...
- PAT甲级——A1121 Damn Single【25】
"Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...
- PAT_A1121#Damn Single
Source: PAT A1121 Damn Single (25 分) Description: "Damn Single (单身狗)" is the Chinese nickn ...
- 1121 Damn Single (25 分)
1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...
- linux-关机出现Telling INIT to go to single user mode.无法关机
运行/sbin/shutdown now最后显示:Telling INIT to go to single user mode.INIT:Going single userINIT:Sending g ...
- [LeetCode] Single Number III 单独的数字之三
Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...
- [LeetCode] Single Number II 单独的数字之二
Given an array of integers, every element appears three times except for one. Find that single one. ...
- [LeetCode] Single Number 单独的数字
Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...
- First,FirstOrDefault,Single,SingleOrDefault的区别
操作符 如果源序列是空的 源序列只包含一个元素 源序列包含多个元素 First 抛异常 返回该元素 返回第一个元素 FirstOrDefault 返回default(TSource) 返回该元素 返回 ...
随机推荐
- day 7-19 Mysql索引原理与查询优化
一,介绍 1.什么是索引? 一般的应用系统,读写比例在10:1左右,而且插入操作和一般的更新操作很少出现性能问题,在生产环境中,我们遇到最多的,也是最容易出问题的,还是一些复杂的查询操作,因此对查询语 ...
- Day 4-7 -configparser模块
此模块用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser. 常用方法: import configparser conf = configpar ...
- Python 基础之----网络编程
阅读目录 一 客户端/服务端架构 二 osi七层 三 socket层 四 socket是什么 五 套接字发展史及分类 六 套接字工作流程 七 基于TCP的套接字 八 基于UDP的套接字 九 粘包现象 ...
- cookie,localStorage和sessionStorage区别
三者的异同 特性 Cookie localStorage sessionStorage 数据的生命期 一般由服务器生成,可设置失效时间.如果在浏览器端生成Cookie,默认是关闭浏览器后失效 除非被清 ...
- sublime text3安装代码格式化的步骤
1.首先查看有没有安装package control插件,若没有,进行此链接操作——http://blog.csdn.net/kongguyoulan523/article/details/51144 ...
- Java之ArrayList自定义排序,通过实现comparator比较器接口
两种排序方式: 1.实体类实现Comparable接口,重写compareTo(T o)方法,在其中定义排序规则,那么就可以直接调用Collections.sort()来排序对象数组 2.在调用方法的 ...
- webpack模塊打包機
https://blog.csdn.net/qq_38277366/article/details/82907894
- vue-cli:渲染过程理解2(vue init webpack方式创建)
main.js: 入口文件 import Vue from 'vue' //引入node_modules中的vue import App from './App' //引入当前路径(src)下的App ...
- MIUI(ADUI)关闭广告推送步骤方法
MIUI自从到了版本MIUI8之后,系统增加了各种推送,让人们所诟病.很多消费者因为这个原因,不再考虑小米手机,尽管小米手机确实很便宜. 下面就说一下如何关闭所有的MIUI 8的广告推送.方法源自MI ...
- Springboot学习问题记录
1.spring boot与cloud构建微服务,返回数据从json变成了xml 问题:本身spingboot项目是用@RestController注解,返回结果也是json格式,但是结合spring ...