PAT B1072 Mensaje de apertura (20 puntos)

Inserte la descripción de la imagen aquí
Las preguntas de nivel B están bien sin violencia cerebral, y definitivamente no se agotarán ~
Nota: El punto de prueba 2 necesita controlar el formato numérico y generar 4 números.

#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;
}

Supongo que te gusta

Origin blog.csdn.net/weixin_45964844/article/details/113870175
Recomendado
Clasificación