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;
}
相关推荐
To_OC4 小时前
LC 131 分割回文串:刚学回溯时,我连怎么切字符串都想不明白
javascript·算法·leetcode
炸膛坦客5 小时前
单片机/C/C++八股:(二十六)IIC 专题(I²C)---- 上集
c语言·c++·单片机
旖-旎5 小时前
LeetCode 518:零钱兑换||(完全背包)—— 题解
c++·算法·leetcode·动态规划·背包问题
灯澜忆梦5 小时前
GO_并发编程---定时器
开发语言·后端·golang
-银雾鸢尾-6 小时前
C#中的StringBuilder相关方法
开发语言·c#
To_OC6 小时前
LC 42 接雨水:暴力超时卡半天?前后缀数组一用就通了
javascript·算法·leetcode
Henry Zhu1236 小时前
C++中的特殊成员函数与智能指针
c++
-银雾鸢尾-6 小时前
C#中结构体与类的区别;抽象类与接口的区别
开发语言·c#
delishcomcn7 小时前
AI视觉识别+分切算法:电化铝缺陷检测与裁切一体化解锁
人工智能·算法
触底反弹7 小时前
深入理解大模型采样:Temperature、Top-K、Top-P 的原理与实战
人工智能·算法·面试