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;
}
相关推荐
凤年徐37 分钟前
【数据结构初阶】单链表
c语言·开发语言·数据结构·c++·经验分享·笔记·链表
木子.李3475 小时前
排序算法总结(C++)
c++·算法·排序算法
闪电麦坤956 小时前
数据结构:递归的种类(Types of Recursion)
数据结构·算法
小熊猫写算法er6 小时前
终极数据结构详解:从理论到实践
数据结构
Gyoku Mint6 小时前
机器学习×第二卷:概念下篇——她不再只是模仿,而是开始决定怎么靠近你
人工智能·python·算法·机器学习·pandas·ai编程·matplotlib
纪元A梦6 小时前
分布式拜占庭容错算法——PBFT算法深度解析
java·分布式·算法
px不是xp7 小时前
山东大学算法设计与分析复习笔记
笔记·算法·贪心算法·动态规划·图搜索算法
-qOVOp-7 小时前
408第一季 - 数据结构 - 栈与队列的应用
数据结构
枫景Maple8 小时前
LeetCode 2297. 跳跃游戏 VIII(中等)
算法·leetcode