https://pintia.cn/problem-sets/994805342720868352/problems/994805447855292416
#include<cstdio> #include<iostream> using namespace std; #include<vector> #include<algorithm> const int M=26*26*26*10+1; vector<int> selectCourse[M]; int nameToNum(char name[]) { //把字符串name转换成数字 int id=0; for(int i=0;i<3;i++) { id=id*26+(name[i]-‘A‘); } id=id*10+(name[3]-‘0‘); return id; } int main() { int n,k; char name[5]; scanf("%d%d",&n,&k); for(int i=0;i<k;i++) { int course,x; scanf("%d%d",&course,&x); for(int j=0;j<x;j++) { scanf("%s",name); int id=nameToNum(name); selectCourse[id].push_back(course); } } for(int i=0;i<n;i++) { scanf("%s",name); int id=nameToNum(name); sort(selectCourse[id].begin(),selectCourse[id].end()); printf("%s %d",name,selectCourse[id].size()); for(int j=0;j<selectCourse[id].size();j++) { printf(" %d",selectCourse[id][j]); } printf("\n"); } return 0; }
原文地址:https://www.cnblogs.com/2o2o/p/11366018.html
时间: 2024-11-12 14:49:00