AC代码:
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; const int M = 26*26*26*10+1; vector<int> student[M]; int hanshu(char 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(void) { freopen("in.txt","r",stdin); int n,k; //student's number , course's number char sname[5]; //student's name scanf("%d%d",&n,&k); for(int i=0;i<k;i++){ int course,stn; scanf("%d%d",&course,&stn); for(int j=0;j<stn;j++){ scanf("%s",sname); int id=hanshu(sname); student[id].push_back(course); } } for(int i=0;i<n;i++){ scanf("%s",sname); int id=hanshu(sname); sort(student[id].begin(),student[id].end()); printf("%s %d",sname,student[id].size()); for(int j=0;j<student[id].size();j++){ printf(" %d",student[id][j]); } printf(" "); } fclose(stdin); return 0; }