zoukankan      html  css  js  c++  java
  • 1047 Student List for Course (25)

    Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses.

    Input Specification:

    Each input file contains one test case. For each case, the first line contains 2 numbers: N (<=40000), the total number of students, and K (<=2500), the total number of courses. Then N lines follow, each contains a student's name (3 capital English letters plus a one-digit number), a positive number C (<=20) which is the number of courses that this student has registered, and then followed by C course numbers. For the sake of simplicity, the courses are numbered from 1 to K.

    Output Specification:

    For each test case, print the student name lists of all the courses in increasing order of the course numbers. For each course, first print in one line the course number and the number of registered students, separated by a space. Then output the students' names in alphabetical order. Each name occupies a line.

    Sample Input:

    10 5
    ZOE1 2 4 5
    ANN0 3 5 2 1
    BOB5 5 3 4 2 1 5
    JOE4 1 2
    JAY9 4 1 2 5 4
    FRA8 3 4 2 5
    DON2 2 4 5
    AMY7 1 5
    KAT3 3 5 4 2
    LOR6 4 2 4 1 5
    

    Sample Output:

    1 4
    ANN0
    BOB5
    JAY9
    LOR6
    2 7
    ANN0
    BOB5
    FRA8
    JAY9
    JOE4
    KAT3
    LOR6
    3 1
    BOB5
    4 7
    BOB5
    DON2
    FRA8
    JAY9
    KAT3
    LOR6
    ZOE1
    5 9
    AMY7
    ANN0
    BOB5
    DON2
    FRA8
    JAY9
    KAT3
    LOR6
    ZOE1

    题目大意:给出每个学生选的课程, 输出选择课程的学生, 升序输出
    注意点: 保存学生的名字最小应该为char ch[5]
    思路: 因为学生的名字是固定格式的, 为了减少时间, 把学生的名字hash成整数, 用char stud[18000][5]记录学生的名字, 第一个下标即学生名字对应的hash值
        把每个学生的hash值添加到课程上, 对每一门课程的学生进行排序后输出
     1  #include<stdio.h>
     2 #include<algorithm>
     3 #include<vector>
     4 #include<string.h>
     5 using namespace std;
     6 vector<int> course[2501];
     7 bool cmp(int a,int b){return a<b;}
     8 char stud[180000][5];
     9 int main()
    10 {
    11     int i,j,n,m,k,t,id;
    12     char name[5];
    13     scanf("%d %d",&n,&m);
    14     for(i=0;i<n;i++)
    15     {
    16       scanf("%s %d",name,&k);
    17       id = (name[0]-'A')*26*26*10+(name[1]-'A')*26*10+(name[2]-'A')*10+name[3]-'0';
    18       strcpy(stud[id],name);
    19       for(j=0;j<k;j++)
    20       {
    21           scanf("%d",&t);
    22           course[t].push_back(id);
    23       }
    24     }
    25     for(i=1;i<=m;i++)
    26     {
    27        printf("%d %d
    ",i,course[i].size());
    28        sort(course[i].begin(),course[i].end(),cmp);
    29        for(j=0;j<course[i].size();j++)
    30            printf("%s
    ",stud[course[i][j]]);
    31     }
    32     return 0;
    33 }
    有疑惑或者更好的解决方法的朋友,可以联系我,大家一起探讨。qq:1546431565
  • 相关阅读:
    【华为云技术分享】浅谈服务化和微服务化(上)
    STM32 GPIO的原理、特性、选型和配置
    【华为云技术分享】如何设计高质量软件-领域驱动设计DDD(Domain-Driven Design)学习心得
    【华为云技术分享】如何做一个优秀软件-可扩展的架构,良好的编码,可信的过程
    【华为云技术分享】华为云MySQL新增MDL锁视图特性,快速定位元数据锁问题
    如何使网站支持https
    如何说孩子才会听,怎么听孩子才肯说
    box-sizing布局学习笔记
    vertical-align属性笔记
    Github上整理的日常发现的好资源【转】
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9157246.html
Copyright © 2011-2022 走看看