https://pintia.cn/problem-sets/994805342720868352/problems/994805433955368960 #includecstdio #include vector #include algorithm #include cstring #include iostream using namespace std; const int MAXN= 40010 ; const int MAXC= 2510 ; char name
https://pintia.cn/problem-sets/994805342720868352/problems/994805433955368960
#include<cstdio> #include<vector> #include<algorithm> #include<cstring> #include<iostream> using namespace std; const int MAXN=40010; const int MAXC=2510; char name[MAXN][5]; vector<int> selectCourse[MAXC]; bool cmp(int a,int b) { return strcmp(name[a],name[b])<0; } int main() { int n,k,c,course; scanf("%d %d",&n,&k); for(int i=0;i<n;i++) { scanf("%s %d",name[i],&c); //二维数组的地址 for(int j=0;j<c;j++) { scanf("%d",&course); selectCourse[course].push_back(i); } } for(int i=1;i<=k;i++) { printf("%d %d\n",i,selectCourse[i].size()); sort(selectCourse[i].begin(),selectCourse[i].end(),cmp); for(int j=0;j<selectCourse[i].size();j++) { printf("%s\n",name[selectCourse[i][j]]); } } return 0; }