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;
}
相关推荐
码客-ygluu4 分钟前
X3 LUA 异步分布式微服务集群框架
c++·架构·lua
starzy19901 小时前
深入理解Scala隐式类:扩展方法机制
开发语言·人工智能·scala
M--Y1 小时前
LangGraph 工作流模式
开发语言·javascript·python·langchain·大模型·llm·langgraph
forest_092 小时前
多 Agent 协作第二课:交叉验证≠独立验证
人工智能·python·算法·机器学习·prompt·agi
九英里路3 小时前
protobuf快速上手
网络·c++·中间件·json·谷歌·序列化·protobuf
吴可可1233 小时前
WScript Shell操作注册表详解
开发语言
纪念 2293 小时前
C++ 算法基础 (差分)
开发语言·c++·算法
jyOverQ7 小时前
从零学 JVM(六):垃圾回收算法详解——标记清除、标记复制与标记整理
jvm·算法
码农小河668 小时前
基于PHP的电商后台蜜罐系统
开发语言·php
starzy19908 小时前
深入理解Scala柯里化函数:函数链式变换
开发语言·scala