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;
}
相关推荐
QJtDK1R5a14 小时前
C# 14 中的新增功能
开发语言·c#
大黄说说14 小时前
Java 中 String 为何被设计为不可变?
开发语言
田梓燊14 小时前
leetcode 56
java·算法·leetcode
复园电子14 小时前
KVM与Hyper-V虚拟化环境:彻底解决USB外设映射掉线的底层架构优化
开发语言·架构·php
2301_8035545214 小时前
三大编程语言(Python/Go/C++)项目启动全解析
c++·python·golang
kvo7f2JTy15 小时前
JAVA 设计模式
java·开发语言·设计模式
wunaiqiezixin15 小时前
MyString类的常见面试问题
c++·面试
仍然.15 小时前
多线程---阻塞队列收尾和线程池
java·开发语言·算法
_深海凉_15 小时前
LeetCode热题100-最长公共前缀
算法·leetcode·职场和发展
郝学胜-神的一滴15 小时前
PyTorch自动微分核心解析:从原理到实战实现权重更新
人工智能·pytorch·python·深度学习·算法·机器学习