Opening Message PAT basic 1072 (20 minutes) C ++ test point 12 misinterpretations

One, Title Description

The figure is a school of Shanghai new semester Message: day to drop any man also, we must first delete its micro-Bo, unloading its QQ, sealing their computer, and took the phone, to close its ipad, off their wifi, so bored, then, the net surface, barber, Zhengyi, then remorse, reading, exercise, wise, enlightened, sophisticated. Then Cheng Kung University also!

This question asks you to write a program to help school teachers to check items for all students to help their National Cheng Kung University.

Input format:
input of the first line gives two positive integers N (≤ 1000) and M (≤ 6), respectively, the number of students and the number of kinds of items to be confiscated. The second line gives the number M needs to be confiscated the item number, which number is four digits. Then N lines, each line gives the student's initials (1-4 by the English capital letters), the number of personal items K (0 ≤ K ≤ 10), and the number of K items.

Output formats:
sequential check each student to carry the goods, if there is to be confiscated items, press information and output the information that students need to be confiscated items in the following format (note the end of the line may not have the extra space) :

Initials: Item 1 item number 2 ......

The total number of problems in the last line of output and the total number of students to be confiscated items.

Sample input:
. 4 2
2333 6666
CYLL. 3 1234 2345 3456
the U-. 4 9966 6666 8888 6666
GG 2333 2 7777
JJ. 3 0012 6666 2333

Output Sample:
the U-: 6666 6666
GG: 2333
JJ: 6666 2333
. 3. 5

Second, the code

//1072
#define _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>
#include<set>
#include<string>
#include<iostream>
using namespace std;

int main()
{
	int n, m,temp;
	cin >> n >> m;
	set<int> a;
	for (int i = 0; i < m; i++)
	{
		cin >> temp;
		a.insert(temp);
	}
	bool flag;
	string name;
	int num,countstu=0,countmono=0;
	for (int i = 0;i < n; i++)
	{
		flag = false;
		cin >> name>>num;

		for (int j = 0; j < num; j++)
		{
			cin >> temp;
			if (a.find(temp)!=a.end())
			{
				if (!flag)
				{
					cout << name << ":";
					flag = 1;
					countstu++;
					
				}
				//cout << " " << temp;//测试点2错误处,应输出4位数字
				printf(" %04d", temp);
				countmono++;
			}
		}
		if(flag)
			cout << endl;
	}
	if (countstu != 0 && countmono != 0)
		cout << countstu << " " << countmono;
	else
		cout << "0 0";//测试点2

	system("pause");
	return 0;
}

Third, the operating results

Here Insert Picture Description

Fourth, the test point 12 error causes and solutions

  • Because the test point 1 topic that is four digits, so I started to accept the type int temp needs to be formatted into four output 0 to fill the seats of the job
  • Test Point 2 At first I thought Output 0 on the line, the result is output 0 0, emmm also okay

Collection title

Here Yo ~

Published 46 original articles · won praise 0 · Views 830

Guess you like

Origin blog.csdn.net/qq_44352065/article/details/104108021