zoukankan      html  css  js  c++  java
  • 数据结构实验之排序七:选课名单

    数据结构实验之排序七:选课名单

    Time Limit: 1000MS Memory Limit: 65536KB

    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
    

    #include<stdio.h>
    #include<string.h>
    #include<malloc.h>
    typedef struct node
    {
        char name[15];
        struct node *next;
    }node;
    node *nam[2010];
    int num[2010];
    int main()
    {
        char str[15];
        int n,m,s,shu;
        int i;
        while(~scanf("%d%d",&n,&m))
        {
            memset(num,0,sizeof(num));
            for(i=0;i<2010;i++)
            {
                nam[i]=(struct node *)malloc(sizeof(struct node));
                nam[i]->next=NULL;
            }
            for(i=0;i<n;i++)
            {
                scanf("%s%d",str,&s);
                while(s--)
                {
                    scanf("%d",&shu);
                    num[shu]++;
                    node *q=(struct node *)malloc(sizeof(struct node));;
                    q->next=NULL;
                    strcpy(q->name,str);
                    node *p=nam[shu];
                    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]);
                node *p=nam[i]->next;
                while(p)
                {
                    printf("%s\n",p->name);
                    p=p->next;
                }
            }
        }
        return 0;
    }

  • 相关阅读:
    Leetcode 50.Pow(x,n) By Python
    Leetcode 347.前K个高频元素 By Python
    Leetcode 414.Fizz Buzz By Python
    Leetcode 237.删除链表中的节点 By Python
    Leetcode 20.有效的括号 By Python
    Leetcode 70.爬楼梯 By Python
    Leetcode 190.颠倒二进制位 By Python
    团体程序设计天梯赛 L1-034. 点赞
    Wannafly挑战赛9 C-列一列
    TZOJ Start
  • 原文地址:https://www.cnblogs.com/CCCrunner/p/11782103.html
Copyright © 2011-2022 走看看