PAT (Advanced Level) 1047. Student List for Course (25)
简单题。
#include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<vector> using namespace std; const int maxn=40000+10; struct X { char name[6]; vector<int>v; }s[maxn]; struct Ans { vector<int>v; }ans[maxn]; bool cmp1(const X&a,const X&b) { return strcmp(a.name,b.name)<0; } int n,m; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%s",s[i].name); int num; scanf("%d",&num); while(num--) { int id; scanf("%d",&id); s[i].v.push_back(id); } } sort(s+1,s+1+n,cmp1); for(int i=1;i<=n;i++) for(int j=0;j<s[i].v.size();j++) ans[s[i].v[j]].v.push_back(i); for(int i=1;i<=m;i++) { printf("%d %d\n",i,ans[i].v.size()); for(int j=0;j<ans[i].v.size();j++) printf("%s\n",s[ans[i].v[j]].name); } return 0; }