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;
}
相关推荐
AresXue21 小时前
你是否也在寻找二进制和字符串的高效转换算法?
算法
Swift社区21 小时前
从 0 到 1 构建一个完整的 AGUI 前端项目的流程在 ESP32 上运行
前端·算法·职场和发展
RTC老炮21 小时前
webrtc弱网-BitrateEstimator类源码分析与算法原理
网络·人工智能·算法·机器学习·webrtc
程序员烧烤21 小时前
【leetcode刷题007】leetcode116、117
算法·leetcode
ghie90901 天前
基于libsvm的支持向量机在MATLAB中的实现
算法·支持向量机·matlab
Rubisco..1 天前
牛客周赛 Round 111
数据结构·c++·算法
兮山与1 天前
算法8.0
算法
高山上有一只小老虎1 天前
杨辉三角的变形
java·算法
Swift社区1 天前
LeetCode 395 - 至少有 K 个重复字符的最长子串
算法·leetcode·职场和发展
hz_zhangrl1 天前
CCF-GESP 等级考试 2025年9月认证C++四级真题解析
开发语言·c++·算法·程序设计·gesp·c++四级·gesp2025年9月