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
  • 相关阅读:
    实验二 结对编程 第二阶段
    实验二 结对编程 第一阶段
    实验一 GIT 代码版本管理
    实验五 单元测试
    实验四 代码审查
    结对编程 第二阶段
    结对编程 第一阶段
    实验一 GIT代码版本管理
    实验五 单元测试
    实验四 代码评审
  • 原文地址:https://www.cnblogs.com/mr-stn/p/9157246.html
Copyright © 2011-2022 走看看