PAT A1047 Student List for Course (25分)

前言

传送门

正文


参考题解

#include<iostream>
#include<vector>
#include<map>
#include<algorithm> 
using namespace std;
/* 本题与PAT1039 Course List for Student相反,给定每名学生的选课列表, 输出每门课程下的选课人数以及选课的学生。 需要注意为了防止最后一个测试点超时,需要弄一个临时的vector指针 来引用其原map的vector,最后进行输出即可。同时注意printf输出vector中的 字符串时直接使用*it->c_str(),或者先用一个string str存储*it,再在输出的时候 使用str.c_str()。 */
map<int,vector<string>> mp;
int main(){
	int n,k,c,ci;
	string name;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		cin>>name>>c;
		for(int j=0;j<c;j++){
			scanf("%d",&ci);
			mp[ci].push_back(name);
		}
	}
	
	vector<string> *v=NULL;
	//string str;
	for(int i=1;i<=k;i++){
		printf("%d %d\n",i,mp[i].size());
		v=&mp[i];
		sort(v->begin(),v->end());
		for(auto it=v->begin();it!=v->end();it++){
			//str=*it;
			//printf("%s\n",str.c_str());
			printf("%s\n",it->c_str()); 
		}
	}
	return 0;

}
全部评论

相关推荐

牛客37185681...:马德,我感觉这是我面过最恶心的公司,一面是两个女hr,说什么实习前几个月属于试用期,试用期过了才能转成正式实习生,我***笑了,问待遇就是不说,问能不能接受全栈,沙币公司
如果可以选,你最想去哪家...
点赞 评论 收藏
分享
08-30 15:51
已编辑
蚌埠坦克学院 Java
狸猫换offer:感觉hr写这段字的时候充满怨气
lastday知无不言
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务