PAT (Basic Level) Practice 1072 开学寄语 (20 分)

题目:1072 开学寄语 (20 分)

来源:PAT (Basic Level) Practice

传送门 1072 开学寄语

题面

PAT (Basic Level) Practice 1072 开学寄语 (20 分)

思路:结构体存储,按要求模拟即可,注意前导零,如果不设置格式会导致测试点2错误

Code

点击查看代码
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
int wjp[10005];
struct node {
	string s;
	int things[1005];
	int num = 0;
}p[2000];
int main() {
	int n, m, x, y, fp = 0, ft = 0;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> x;
		wjp[x] = 3;
	}
	for (int i = 1; i <= n; i++) {
		cin >> p[i].s >> x;
		for (int j = 1; j <= x; j++) {
			cin >> y;
			if (wjp[y] == 3) {
				p[i].num++;
				p[i].things[p[i].num] = y;
				ft++;
			}
		}
		if (p[i].num != 0)fp++;
	}
	for (int i = 1; i <= n; i++) {
		if (p[i].num != 0) {
			cout << p[i].s << ":";
			for (int j = 1; j <= p[i].num; j++) {
				cout<< " " << setfill('0')<<setw(4)<<p[i].things[j];
			}
			cout << "\n";
		}
	}
	cout << fp << " " << ft << '\n';

	return 0;
}
上一篇:XSS-LABS


下一篇:python实现日志输出