C++版浙大PAT乙级1072(20分)测试点2答案错误解决方法

https://pintia.cn/problem-sets/994805260223102976/problems/994805263964422144

 测试点2是要以4位数字的格式输出。这么简单的点居然给忘了!

#include<iostream>
using namespace std;

int main() {
	int n, m, t, w, temp, k, item[10000]={0}, weijin[6], count1=0, count2=0;
	cin >> n >> m;
	string name;
	for(int i=0; i<m; i++){
		cin >> t;
		item[t] = 1;
	}
	for(int i=0; i<n; i++){
		k = 0;
		cin >> name >> w;
		for(int j=0; j<w; j++){
			cin >> temp;
			if(item[temp]==1){
				weijin[k]=temp;
				k ++;
			}
		}
		if(k>0){
			count1 ++;
			cout << name << ": ";
		}
		for(int j=0; j<k; j++){
			count2 ++;
			printf("%04d", weijin[j]);
			if(j<k-1){
				cout << " ";
			}else{
				cout << endl;
			}
		}
	}
	cout << count1 << " " << count2 << endl;
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值