Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
随着学校规模的扩大,学生人数急剧增加,选课名单的输出也成为一个繁重的任务,我校目前有在校生3万多名,两千多门课程,请根据给定的学生选课清单输出每门课的选课学生名单。
Input
输入第一行给出两个正整数N( N ≤ 35000)和M(M ≤ 2000),其中N是全校学生总数,M是课程总数,随后给出N行,每行包括学生姓名拼音+学号后两位(字符串总长度小于10)、数字S代表该学生选课的总数,随后是S个课程编号,约定课程编号从1到M,数据之间以空格分隔。
Output
按课程编号递增的顺序输出课程编号、选课总人数以及选课学生名单,对选修同一门课程的学生按姓名的字典序输出学生名单。数据之间以空格分隔,行末不得有多余空格。
Example Input
5 3
Jack01 2 2 3
Jone01 2 1 3
Anni02 1 1
Harry01 2 1 3
TBH27 1 1
Example Output
1 4
Anni02
Harry01
Jone01
TBH27
2 1
Jack01
3 3
Harry01
Jack01
Jone01
Hint
Author
xam
#include<iostream>
#include<string>
using namespace std;
typedef struct peo
{
string name;
struct peo *next;
}pe;
struct couse
{
int kn,nu;
pe head;
}c[20001];
void inter(string pp,int cc)
{
c[cc].nu++;
pe *pn=new pe,*p,*q;
pn->name=pp;
pn->next=NULL;
p=&(c[cc].head);
while(p->next)
{
if(p->next->name>=pp)
{
break;
}
p=p->next;
}
pn->next = p->next;
p->next =pn;
}
int main()
{
int n,cc;
cin>>n>>cc;
for(int i=1;i<=cc;i++)
{
c[i].kn=i;
c[i].nu=0;
c[i].head.next=NULL;
}
for(int i=0;i<n;i++)
{
string na;
cin>>na;
int t;
cin>>t;
while(t--)
{
int cc;
cin>>cc;
inter(na,cc);
}
}
for(int i=1;i<=cc;i++)
{
cout<<i<<" "<<c[i].nu<<endl;
pe *p=(c[i].head.next);
while(p)
{
cout<<p->name<<endl;
p=p->next;
}
}
return 0;
}