题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1047
题目没难度,说一点,cin cout 最后一个case超时,改c形式, 最后一个case 370ms...
1 #include<cstdio> 2 #include<vector> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 7 struct Node{ 8 char name[10]; 9 }; 10 11 bool comp(Node n1, Node n2){ 12 if(strcmp(n1.name, n2.name) < 0) 13 return true; 14 else 15 return false; 16 } 17 18 vector<vector<Node>> course; 19 20 int main(){ 21 int N,K;scanf("%d%d",&N,&K); 22 course.resize(K); 23 for(int i=0; i<N; ++i){ 24 Node n; int num; 25 scanf("%s%d",n.name,&num); 26 for(int j=0; j<num; ++j){ 27 int c; scanf("%d",&c); 28 course[c-1].push_back(n); 29 } 30 } 31 for(int i=0; i<K; ++i){ 32 int length=course[i].size(); 33 printf("%d %d ", i+1, length); 34 if(length != 0){ 35 sort(course[i].begin(), course[i].end(), comp); 36 for(int j=0; j<length; ++j) 37 printf("%s ", course[i][j].name); 38 } 39 } 40 return 0; 41 }