PAT B 1065 single dog /// attention /// set the output format to use

Single Dogs "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 formats:
given input of the first line of 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 number corresponding to an ID, of 5 digits (from 00000 to 99999), separated by a space between ID; given after a positive integer M (≤ 10 000), the total number of people at the party; then the M line gives guests the ID, separated by a space no title guarantee or bigamy. 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 444,441,000,088,888 222,221,111,123,333

Output Sample:
. 5
10000 23333 444,445,555,588,888

Ideas: first with the hash table index husband put his wife, who put her husband subscript. Because the questions asked will answer output in order, so I will be the party were all set into a container, then combined set of the find function and hash table, if not pair the couple in the set, they are placed in vector. Final output

Note that a pit: id number is from 00000 to 99999. A 0 before the number between 00000 to 10000 should be output, otherwise the penultimate test points can not pass, so here use printf to output.

#include <iostream>
#include <set>
#include <cstdio>
#include <vector>
using namespace std;
int main()
{
	int hash[99999] = {0};
	int pair = 0;
	cin >> pair;
	for (int i = 0; i < pair; i++)
	{
		int hus, wif;
		cin >> hus >> wif;
		hash[hus] = wif;
		hash[wif] = hus;
	}
	set<int> st;
	int num;
	cin >> num;
	for (int i = 0; i < num; i++)
	{
		int n;
		cin >> n;
		st.insert(n);
	}
	vector<int> vec;
	for (set<int>::iterator it = st.begin(); it != st.end(); it++)
		if (st.find(hash[*it]) == st.end()) //find()函数如果没找到,则返回end()所在迭代器
			vec.push_back(*it);
	printf("%d\n", vec.size());
	for (int i = 0; i < vec.size(); i++)
	{
		if (i != 0) printf(" ");
		printf("%05d", vec[i]);  //注意使用printf
	}
	return 0;
}

Summary: The first to come up with their own reasons not pass the test point, a little excited!

Published 101 original articles · won praise 1 · views 1952

Guess you like

Origin blog.csdn.net/weixin_43318827/article/details/105385344