【PAT甲级】1047 Student List for Course (25 分)

题意:

输入两个正整数N和K(N<=40000,K<=2500),接下来输入N行,每行包括一个学生的名字和所选课程的门数,接着输入每门所选课程的序号。输出每门课程有多少学生选择并按字典序输出学生的名字。

AAAAAccepted code:

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 string s[40007];
 5 vector<string>v[2507];
 6 int main(){
 7     ios::sync_with_stdio(false);
 8     cin.tie(NULL);
 9     cout.tie(NULL);
10     int n,k;
11     cin>>n>>k;
12     for(int i=1;i<=n;++i){
13         cin>>s[i];
14         int x;
15         cin>>x;
16         for(int j=1;j<=x;++j){
17             int y;
18             cin>>y;
19             v[y].push_back(s[i]);
20         }
21     }
22     for(int i=1;i<=k;++i)
23         sort(v[i].begin(),v[i].end());
24     for(int i=1;i<=k;++i){
25         cout<<i<<" "<<v[i].size();
26         for(auto it:v[i])
27             cout<<"
"<<it;
28         if(i!=k)
29             cout<<"
";
30     }
31     return 0;
32 }
保持热爱 不懈努力 不试试看怎么知道会失败呢(划掉) 世上无难事 只要肯放弃(划掉)
原文地址:https://www.cnblogs.com/ldudxy/p/11614737.html