#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node
{
char name[11];
struct node*next;
};
int main()
{
int n,m,a,x;//n为学生总人数,m为课程总数
char str[12];
scanf("%d%d",&n,&m);
struct node*p,*q;
struct node*head[2001];//存储每门课学生姓名
int i;
for(i=1;i<=2000;i++)
{
head[i]=(struct node*)malloc(sizeof(struct node));
head[i]->next=NULL;//初始化 目前没有学生
}
int num[2001];//存储选修每门课的人数
memset(num,0,sizeof(num));
while(n--)
{
scanf("%s %d",str,&a);//s为姓名,a为此学生选课总数
while(a--)//a个课程编号
{
scanf("%d",&x);
num[x]++;//次门课选修人数纪录
p=head[x];
q=(struct node*)malloc(sizeof(struct node));
strcpy(q->name,str);
while(p->next)
{
if(strcmp(q->name,p->next->name)<0)
break;
p=p->next;
}
q->next=p->next;
p->next=q;
}
}
for(i=1;i<=m;i++)
{
printf("%d %d\n",i,num[i]);
p=head[i]->next;
while(p)
{
printf("%s\n",p->name);
p=p->next;
}
}
return 0;
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交