1072 开学寄语 (20 分)

注意

  • 第三个测试点容易出错,题目说的是4位数字,所以输出的时候就必须是四位,即读入的是0721,不注意的话,会直接输出721,这样测试点就不通过。

2021.04.13

#include <iostream>
#include <unordered_set>
using namespace std;
int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	unordered_set<int> st;
	int a;
	for(int i = 0; i < m; i++){
		scanf("%d", &a);
		st.insert(a);
	}
	
	int totalStu = 0, total = 0;
	char  name[16];
	int cnt = 0;
	for(int i = 0; i < n; i++){
		scanf("%s %d", name, &cnt);
		bool first = true;
		for(int j = 0; j < cnt; j++){
			scanf("%d", &a);
			if(st.count(a)){
				total++;
				if(first){
					printf("%s: %04d", name, a);
					first = false;
				}else{
					printf(" %04d", a);
				}
			}
		}
		if(!first) {
			totalStu++;
			printf("\n");
		}
	}
	printf("%d %d", totalStu, total);
	
	return 0;
}

C++

#include<cstdio>
#include<cstring>
const int maxn=10005;
int main(){
	int N,M,num,k;
	char name[5];
	scanf("%d%d",&N,&M);
	int item[maxn];
	memset(item,0,sizeof(item));
	for(int i=0;i<M;i++){
		scanf("%d",&num);
		item[num]=1;
	}
	int cntp=0,cntt=0;
	for(int i=0;i<N;i++){
		scanf("%s %d",name,&k);
		int tag=1;
		for(int j=0;j<k;j++){
			scanf("%d",&num);
			if(item[num]==1) {
				cntt++;
				if(tag==1){
					printf("%s:",name);
					tag=2;
				}
				printf(" %04d",num);
			}	
		}
		if(tag==2) {
			cntp++;	
			printf("\n");
		}
	}
	printf("%d %d",cntp,cntt);
	
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值