"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的更多相关文章

  1. PAT A1121 Damn Single (25 分)——set遍历

    "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...

  2. PAT甲级——A1121 Damn Single【25】

    "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...

  3. PAT_A1121#Damn Single

    Source: PAT A1121 Damn Single (25 分) Description: "Damn Single (单身狗)" is the Chinese nickn ...

  4. 1121 Damn Single (25 分)

    1121 Damn Single (25 分) "Damn Single (单身狗)" is the Chinese nickname for someone who is bei ...

  5. 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 ...

  6. [LeetCode] Single Number III 单独的数字之三

    Given an array of numbers nums, in which exactly two elements appear only once and all the other ele ...

  7. [LeetCode] Single Number II 单独的数字之二

    Given an array of integers, every element appears three times except for one. Find that single one. ...

  8. [LeetCode] Single Number 单独的数字

    Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...

  9. First,FirstOrDefault,Single,SingleOrDefault的区别

    操作符 如果源序列是空的 源序列只包含一个元素 源序列包含多个元素 First 抛异常 返回该元素 返回第一个元素 FirstOrDefault 返回default(TSource) 返回该元素 返回 ...

随机推荐

  1. C++中String类的字符串分割实现

    最近笔试,经常遇到需要对字符串进行快速分割的情景,主要是在处理输入的时候,而以前练习算法题或笔试,很多时候不用花啥时间考虑测试用例输入的问题.可是C++标准库里面没有像java的String类中提供的 ...

  2. 剑指offer(16)栈的压入、弹出序列

    题目: 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈 ...

  3. Your branch is ahead of 'origin/master' by 2 commits.

    遇到这种问题,表示在你之前已经有2个commit而没有push到远程分支上,所以需要先git push origin **将本地分支提到远程仓库.也可以直接git reset --hard HEAD~ ...

  4. Form组件归类

    一.Form类 创建Form类时,主要涉及到 [字段] 和 [插件],字段用于对用户请求数据的验证,插件用于自动生成HTML; 1.Django内置字段如下: 1 Field 2 required=T ...

  5. socket基础编程-2

    client端: import socket while True: client=socket.socket(socket.ANET,socket.SOCK_STREAM) client.conne ...

  6. python学习笔记(2)--基本语法元素

    来看一个非常简单的温度转换程序 #Tempconvert.py tempstr = input("输入:") if tempstr[-1] in ['F', 'f']: C = ( ...

  7. 生成统计数据并导出Excel

    需求:看如下表格的统计需求 生产调度中心部门需要从IT技术部门得到这些统计数据 步骤: (1)获取所有的子公司列表 (2)遍历所有的子公司,获取每个子公司的库存信息 (3)遍历所有的库存信息,并对库存 ...

  8. Echarts使用Ajax异步获得数据的前端json格式转化问题

    利用Ajax获取后台传来的data,官网都有example 但如果后台传来的数据是String格式的,则应该在Ajax的done方法中第一句加上格式转换的语句 data = JSON.parse(da ...

  9. 算法题 -- 输入一个Long数组,按要求输出一个等长的Long数组

    /** * 输入一个Long数组,按要求输出一个等长的Long数组 * 输出数组的元素值等于,输入数组除相同下标外其他元素的积 * 如:输入[1, 2, 3, 4], 输出[24, 12, 8, 6] ...

  10. [oracle] to_date() 与 to_char() 日期和字符串转换

    to_date("要转换的字符串","转换的格式")   两个参数的格式必须匹配,否则会报错. 即按照第二个参数的格式解释第一个参数. to_char(日期,& ...