PAT刷題分類之STL部分
阿新 • • 發佈:2019-02-03
【1】1047 Student List for Course(25 分)
思路:無
#include<cstdio> #include<iostream> #include<algorithm> #include<vector> #include<cstring> #define MAX1 40001 #define MAX2 2501 using namespace std; char name[MAX1][5]; vector<int> cr[MAX2]; bool cmp(int a,int b){ return strcmp(name[a],name[b])<0; } int main() { int N,K,m,nb; scanf("%d%d",&N,&K); for(int i=0;i<N;i++){ scanf("%s%d",name[i],&m); for(int j=0;j<m;j++){ scanf("%d",&nb); cr[nb].push_back(i); } } for(int i=1;i<=K;i++){ printf("%d %d\n",i,cr[i].size()); sort(cr[i].begin(),cr[i].end(),cmp); for(int j=0;j<cr[i].size();j++) printf("%s\n",name[cr[i][j]]); } return 0; }