1039. Course List for Student

#include<algorithm>
#include<string>
#include<unordered_map>
#include<cstdio>
#include<vector>
using namespace std;
unordered_map<int,vector<int>>hehe;
int s2i(char*p){
  int val=p[3]-'0';
  for(int i=2;i>=0;--i) val=val*26+p[i]-'A';
  return val;
}
int main(){
  int n,m;scanf("%d%d",&m,&n);
  char name[5];
  while(n--){
    int course,cnt;
    scanf("%d%d",&course,&cnt);
    while(cnt--){
      scanf("%s",name);
      hehe[s2i(name)].push_back(course);
    }//while
  }//while
  while(m--){
    scanf("%s",name);
    printf("%s",name);
    auto &x=hehe[s2i(name)];
    if(x.size()){
      sort(x.begin(),x.end());
      cout<<' '<<x.size();
      for(auto &y:x)cout<<' '<<y;
      cout<<endl;
    }//if
    else cout<<' '<<0<<endl;
  }//while
}


你可能感兴趣的:(1039. Course List for Student)