[PAT] Class 1047 Student List for Course (25 points)

Meaning of the questions:

Enter two positive integers N and K (N <= 40000, K <= 2500), the next N input lines, each including a student's name the number of gates and the selected course, and then enter the serial number of each gate of the selected course . The output of each course how many students select and output lexicographically student's name.

Code:

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string s[40007];
vector<string>v[2507];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,k;
cin>>n>>k;
for(int i=1;i<=n;++i){
cin>>s[i];
int x;
cin>>x;
for(int j=1;j<=x;++j){
int y;
cin>>y;
v[y].push_back(s[i]);
}
}
for(int i=1;i<=k;++i)
sort(v[i].begin(),v[i].end());
for(int i=1;i<=k;++i){
cout<<i<<" "<<v[i].size();
for(auto it:v[i])
cout<<"\n"<<it;
if(i!=k)
cout<<"\n";
}
return 0;
}

Guess you like

Origin www.cnblogs.com/ldudxy/p/11614737.html