其他分享
首页 > 其他分享> > PAT (Basic Level) Practice 1072 开学寄语 (20 分)

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

作者:互联网

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

来源:PAT (Basic Level) Practice

传送门 1072 开学寄语

题面

image

思路:结构体存储,按要求模拟即可,注意前导零,如果不设置格式会导致测试点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;
}

标签:Level,int,Practice,1072,++,num,include,wjp
来源: https://www.cnblogs.com/w0x59-h/p/15858158.html