当前位置 : 主页 > 网页制作 > HTTP/TCP >

STL_A1047 Student List for Course (25 分)

来源:互联网 收集:自由互联 发布时间:2021-06-16
https://pintia.cn/problem-sets/994805342720868352/problems/994805433955368960 #includecstdio #include vector #include algorithm #include cstring #include iostream using namespace std; const int MAXN= 40010 ; const int MAXC= 2510 ; char name

https://pintia.cn/problem-sets/994805342720868352/problems/994805433955368960

#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;

const int MAXN=40010;
const int MAXC=2510;
char name[MAXN][5];
vector<int> selectCourse[MAXC];

bool cmp(int a,int b) {
    return strcmp(name[a],name[b])<0;
}

int main() {
    int n,k,c,course;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++) {
        scanf("%s %d",name[i],&c); //二维数组的地址
        for(int j=0;j<c;j++) {
            scanf("%d",&course);
            selectCourse[course].push_back(i);
        }
    }

    for(int i=1;i<=k;i++) {
        printf("%d %d\n",i,selectCourse[i].size());
        sort(selectCourse[i].begin(),selectCourse[i].end(),cmp);
        for(int j=0;j<selectCourse[i].size();j++) {
            printf("%s\n",name[selectCourse[i][j]]);
        }
    }
    return 0;
}
网友评论