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;
}
相关推荐
地平线开发者6 小时前
【模型轻量化专题】衡量模型轻量性的指标
算法
学习星球9 小时前
OFDM技术精讲:正交性推导、循环前缀原理与80行Python链路仿真(附实测数据)
算法·面试·前端框架
alphaTao15 小时前
LeetCode 每日一题 2026/8/24-2026/8/30
python·算法·leetcode
Interview Aid11216 小时前
TikTok OA 四题分享|半小时内 AC,题目基本都是实现题
java·开发语言·算法·面试·职场和发展
顶点多余1 天前
那些在算法中适合巩固的知识点---1
java·前端·算法
AI情绪识别开源1 天前
检信 ALLEMOTION OS 加密打包可执行程序 — 全面测试报告版本: v1.3功能测试 / 性能测试 /
开发语言·数据结构·人工智能·功能测试
罗西的思考1 天前
【Agentic RL / 强化学习框架】Molt 设计解读
人工智能·算法·机器学习
hahaha60161 天前
HLS高层次综合设计技巧--C++类和模板
图像处理·人工智能·算法·计算机视觉
多弗朗皮卡丘1 天前
算法详解4:买卖股票的最佳时机系列(上)
算法
维克兜率天1 天前
【维克】动量指标家族:RSI、ROC、CCI、Momentum全面解析
python·算法