Click on the link full solution summary PAT B -AC
Title:
"Single Dog" is the Chinese term of endearment for a single person. This question you find guests from the single large party of thousands of people in order to give special care.
Input format:
input of the first row is given a positive integer N (≤ 50 000), is the number of known couple / partner; then N rows, each row is given a couple / partner - for convenience, each corresponding to an ID number, digits 5, between the partition ID (from 00,000 to 99,999) by a space; after a given positive integer M (≤ 10 000), the total number of the party; subsequently given the M row guests the ID, separated by a space. Topic ensure no bigamy or foot boats.
Output Format:
First, the single output line of a first total number of guests; followed by a second line ID is incremented by the order listed in the single guests. With a space between the partition ID, and last row may not have extra space.
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
My code:
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstring>
#include<sstream>
using namespace std;
//有的时候题目是一起做的,所以会有不需要的头文件
int main()
{
int pairs[100010]={0};
int member[100010]={0};
int N;
int num_dog=0;
cin>>N;
for(int i=0;i<N;i++)
{
int a,b;
cin>>a>>b;
if(a==0)a=100000;
if(b==0)b=100000;
pairs[a]=b;
pairs[b]=a;
}
cin>>N;
for(int i=0;i<N;i++)
{
int a;
cin>>a;
if(a==0)a=100000;
member[a]=1;
}
//delete pairs
for(int i=1;i<100000;i++)
{
if(member[i]&&member[pairs[i]])
{
member[i]=0;
member[pairs[i]]=0;
}
else if(member[i])
{
num_dog++;
}
}
printf("%d\n",num_dog);
if(member[100000])
{
cout<<"00000";
num_dog--;
if(num_dog)cout<<" ";
}
for(int i=1;i<100000;i++)
{
if(member[i])
{
printf("%05d",i);
num_dog--;
if(num_dog)cout<<" ";
else break;
}
}
return 0;
}