PAT B1072 Opening Message (20 points)

Insert picture description here
Level B questions are just fine without brain violence, and they will definitely not time out~
Note: Test point 2 needs to control the number format and output 4 numbers.

#include <cstdio>
#include <string>
#include <iostream>
using namespace std;

bool hashTable[10000] = {
    
    false};

int main(){
    
    
	int m, n;
	scanf("%d %d", &n, &m);
	
	for(int i=0; i<m; i++){
    
    
		int x;
		scanf("%d", &x);
		hashTable[x] = true;
	}
	int snum = 0, tnum = 0;
	for(int i=0; i<n; i++){
    
    
		string name;
		int num;
		int flag = 0;
		cin >> name;
		scanf("%d", &num);
		int thing[num];
		for(int j=0; j<num; j++){
    
    
			scanf("%d", &thing[j]);
		}
		for(int j=0; j<num; j++){
    
    
			int index = thing[j];
			if(hashTable[index]){
    
    
				cout << name << ":";
				flag = 1;
				snum++;
				break;
			}
		}
		for(int j=0; j<num; j++){
    
    
			int index = thing[j];
			if(hashTable[index]){
    
    
				printf(" %04d", index);
				tnum++;
			}
		}
		if(flag) cout << endl;
	}
	cout << snum << " " << tnum;
	
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45964844/article/details/113870175