1072 开学寄语 (20分)(详细代码和测试点2分析)

注意测试点2,当物品编号为0123的时候,输出的时候也要是四位数字0123
``

#include <iostream>
#include<cstdio>
#include<string>
using namespace std;
int goods[10000] = {0};
string s;
int main()
{
	int n, m, num1 = 0,num2=0;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int k;
		cin >> k;
		goods[k] = 1;
	}
	for (int i = 0; i < n; i++) {
		bool flag = true;
		int k,t;
		cin >> s >> k;
		for (int j = 0; j < k; j++) {
			cin >> t;
			if (goods[t] == 1 && flag == true) {
				num1++;
				num2++;
				flag = false;
				cout << s << ": ";
				printf("%04d", t);
			}
			else if (goods[t] == 1 && flag != true) {
				printf(" %04d", t);
				num2++;
			}
		}
		if(flag==false)
		cout << endl;

	}
	cout << num1 << " " << num2;
}
发布了17 篇原创文章 · 获赞 0 · 访问量 179

猜你喜欢

转载自blog.csdn.net/w17390956947/article/details/105004083