1047 Student List for Course 25

cpp 复制代码
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int K = 2510;
const int maxn = 40010;
vector<int> courses[K];
char names[maxn][5];
bool cmp(int a, int b){
    return strcmp(names[a], names[b]) < 0;
}
int main() {
    int N,M;
    scanf("%d%d", &N, &M);
    for(int i = 0; i < N; i++){
        int num;
        scanf("%s %d", names[i], &num);
        for(int j = 0; j < num; j++){
            int id;
            scanf("%d", &id);
            courses[id].push_back(i);
        }
    }
    for(int i = 1; i <= M; i++){
        printf("%d %d\n", i, courses[i].size());
        sort(courses[i].begin(), courses[i].end(), cmp);
        for(int j = 0; j < courses[i].size(); j++){
            printf("%s\n", names[courses[i][j]]);
        }
    }
    return 0;
}
相关推荐
songx_996 分钟前
leetcode10(跳跃游戏 II)
数据结构·算法·leetcode
先做个垃圾出来………1 小时前
差分数组(Difference Array)
java·数据结构·算法
hansang_IR1 小时前
【题解】洛谷 P4286 [SHOI2008] 安全的航线 [递归分治]
c++·数学·算法·dfs·题解·向量·点积
乐迪信息1 小时前
乐迪信息:AI摄像机在智慧煤矿人员安全与行为识别中的技术应用
大数据·人工智能·算法·安全·视觉检测
多恩Stone2 小时前
【3DV 进阶-2】Hunyuan3D2.1 训练代码详细理解下-数据读取流程
人工智能·python·算法·3d·aigc
dragoooon342 小时前
[数据结构——lesson5.1链表的应用]
数据结构·链表
惯导马工3 小时前
【论文导读】IDOL: Inertial Deep Orientation-Estimation and Localization
深度学习·算法
老姜洛克3 小时前
自然语言处理(NLP)之n-gram从原理到实战
算法·nlp
CoovallyAIHub4 小时前
基于YOLO集成模型的无人机多光谱风电部件缺陷检测
深度学习·算法·计算机视觉
CoovallyAIHub4 小时前
几十个像素的小目标,为何难倒无人机?LCW-YOLO让无人机小目标检测不再卡顿
深度学习·算法·计算机视觉