美文网首页
1039 Course List for Student (25

1039 Course List for Student (25

作者: 量化啦啦啦 | 来源:发表于2020-02-17 16:51 被阅读0次
image.png
/*
Sample Input:
11 5
4 7
BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
1 4
ANN0 BOB5 JAY9 LOR6
2 7
ANN0 BOB5 FRA8 JAY9 JOE4 KAT3 LOR6
3 1
BOB5
5 9
AMY7 ANN0 BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1
ZOE1 ANN0 BOB5 JOE4 JAY9 FRA8 DON2 AMY7 KAT3 LOR6 NON9
Sample Output:
ZOE1 2 4 5
ANN0 3 1 2 5
BOB5 5 1 2 3 4 5
JOE4 1 2
JAY9 4 1 2 4 5
FRA8 3 2 4 5
DON2 2 4 5
AMY7 1 5
KAT3 3 2 4 5
LOR6 4 1 2 4 5
NON9 0
 */
#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 26 * 26 * 26 * 10 + 10;        //???????
vector<int> stu[maxn];
int getId(char *name) {
    int id = 0;
    for (int i = 0; i < 3; i++) {
        id = 26 * id + (name[i] - 'A');
    }
    id = id * 10 + (name[3] - '0');
    return id;
}
int main() {
    int numStu, numCourse = 0, indexCourse, numStuCourse, id = 0;
    char name[5];
    scanf("%d %d", &numStu, &numCourse);
    for (int i = 0; i < numCourse; i++) {
        scanf("%d %d", &indexCourse, &numStuCourse);for (int j = 0; j < numStuCourse; j++) {
            scanf("%s", name);
            id = getId(name);
            stu[id].push_back(indexCourse);
        }
    }
    for (int i = 0; i < numStu; i++) {
        scanf("%s", name);
        id = getId(name);
        sort(stu[id].begin(), stu[id].end());
        cout << name <<" "<< stu[id].size();\
        for (int j = 0; j < stu[id].size(); j++)
            cout <<" "<< stu[id][j];
        printf("\n");
    }
    return 0;
}

相关文章

网友评论

      本文标题:1039 Course List for Student (25

      本文链接:https://www.haomeiwen.com/subject/idxifhtx.html