pat 1039 Course List for Student(23分)

30 篇文章 0 订阅

简单题,定义一个map<string, vector<int> >即可。将对应学生的选课进行排序,但最后一点总是超时,换成scanf和printf,还是超。以后再看吧。

代码:

//1039 20:28-21:12
#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

map<string, vector<int> > m;
int main()
{
	int n,i,k,j,index,num;
	freopen("C:\\Documents and Settings\\Administrator\\桌面\\input.txt","r",stdin);

	cin>>n>>k;
	char s[6];
	/*string sname;*/
	for(i=0;i<k;i++){
		cin>>index>>num;
		for(j=0;j<num;j++){
			//cin>>sname;
			getchar();
			scanf("%s",s);
			string tname(s);
			m[tname].push_back(index);

		}
	}
	for(i=0;i<n;i++){
		getchar();
		scanf("%s",s);
		string sname(s);
		//cin>>sname;

		sort(m[sname].begin(),m[sname].end());
		//cout<<sname<<" "<<m[sname].size();
		printf("%s %d",sname.c_str(),m[sname].size());
		for(j=0;j!=m[sname].size();j++){
			//cout<<" "<<m[sname][j];
			printf(" %d",m[sname][j]);
		}
		printf("\n");
		//cout<<endl;
	}
	return 0;
}


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值