1039 Course List for Student 25

cpp 复制代码
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int range = 26*26*26*10 + 5;
vector<int> Stu[range];

int getId(char s[]){
    int res = 0;
    for(int i = 0; i < 3; i++){
        res = res * 26 + (s[i] -'A');
    }
    res = res * 10 + s[3] - '0';
    return res;
}

int main() {
    char name[5];
    int N,M;
    scanf("%d%d", &N, &M);
    for(int i = 0; i < M; i++){
        int classId, chooseNum;
        scanf("%d%d", &classId, &chooseNum);
        for(int j = 0; j < chooseNum; j++){
            scanf("%s", name);
            Stu[getId(name)].push_back(classId);
        }
    }
    for(int i = 0; i < N; i++){
        scanf("%s", name);
        int id = getId(name);
        sort(Stu[id].begin(), Stu[id].end());
        printf("%s %d", name, Stu[id].size());
        for(int j = 0; j < Stu[id].size(); j++){
            printf(" %d", Stu[id][j]);
        }
        printf("\n");
    }
    return 0;
}
相关推荐
wjs20246 分钟前
Swift 类型转换
开发语言
前端小L26 分钟前
贪心算法专题(十):维度权衡的艺术——「根据身高重建队列」
javascript·算法·贪心算法
方得一笔26 分钟前
自定义常用的字符串函数(strlen,strcpy,strcmp,strcat)
算法
秃了也弱了。28 分钟前
python实现定时任务:schedule库、APScheduler库
开发语言·python
weixin_4407305038 分钟前
java数组整理笔记
java·开发语言·笔记
Xの哲學1 小时前
Linux SMP 实现机制深度剖析
linux·服务器·网络·算法·边缘计算
Thera7771 小时前
状态机(State Machine)详解:原理、优缺点与 C++ 实战示例
开发语言·c++
linux开发之路1 小时前
C++高性能日志库开发实践
c++·c++项目·后端开发·c++新特性·c++校招
wuk9981 小时前
使用PCA算法进行故障诊断的MATLAB仿真
算法·matlab
额呃呃1 小时前
二分查找细节理解
数据结构·算法