STL_A1039 Course List for Student (25 分)

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

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

const int M=26*26*26*10+1;
vector<int> selectCourse[M];

int nameToNum(char name[]) { //把字符串name转换成数字
    int id=0;
    for(int i=0;i<3;i++) {
        id=id*26+(name[i]-‘A‘);
    }
    id=id*10+(name[3]-‘0‘);
    return id;
}

int main() {
    int n,k;
    char name[5];
    scanf("%d%d",&n,&k);
    for(int i=0;i<k;i++) {
        int course,x;
        scanf("%d%d",&course,&x);
        for(int j=0;j<x;j++) {
            scanf("%s",name);
            int id=nameToNum(name);
            selectCourse[id].push_back(course);
        }
    }
    for(int i=0;i<n;i++) {
        scanf("%s",name);
        int id=nameToNum(name);
        sort(selectCourse[id].begin(),selectCourse[id].end());
        printf("%s %d",name,selectCourse[id].size());
        for(int j=0;j<selectCourse[id].size();j++) {
            printf(" %d",selectCourse[id][j]);
        }
        printf("\n");
    }
    return 0;
}

原文地址:https://www.cnblogs.com/2o2o/p/11366018.html

时间: 2024-11-12 14:49:00

STL_A1039 Course List for Student (25 分)的相关文章

PAT Advanced 1039 Course List for Student (25分) (STL)

Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query. Input Specification: Each input file

【PAT甲级】1039 Course List for Student (25 分)(vector嵌套于map,段错误原因未知)

题意: 输入两个正整数N和K(N<=40000,K<=2500),分别为学生和课程的数量.接下来输入K门课的信息,先输入每门课的ID再输入有多少学生选了这门课,接下来输入学生们的ID.最后N次询问,输入学生的ID输出该学生选了多少们课,输出所选课程的数量,按照递增序输出课程的ID. trick: 第5个数据点出现段错误,把原本以map存学生对应ID再映射vector存储该学生所选课程改成vector嵌套在map内,就没有段错误的问题出现,疑似映射过程中指针漂移??? 代码: #define H

浙大pat1039 Course List for Student(25 分)

1039 Course List for Student(25 分) Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query. In

1047 Student List for Course (25 分)

1047 Student List for Course (25 分) Zhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses. Input Specification: E

1012 The Best Rank (25)(25 分)

1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algebra), and E - English. At the mean ti

PAT 甲级 1083 List Grades (25 分)

1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grades are in a given interval. I

1083 List Grades (25 分)排序

1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grades are in a given interval. I

1036 Boys vs Girls (25 分)

1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students. Input Specification: Each input file contains one test case. Each case contai

1109 Group Photo (25 分)

1109 Group Photo (25 分) Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following: The number of people in each row must be N/K (round down to the nearest integer), with all the extra peop