点击链接PAT甲级-AC全解汇总
题目:
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 Algrbra), and E
- English. At the mean time, we encourage students by emphasizing on their best ranks – that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.
For example, The grades of C
, M
, E
and A
- Average of 4 students are given as the following:
StudentID C M E A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91
Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.
Input Specification:
Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (≤2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C
, M
and E
. Then there are M lines, each containing a student ID.
Output Specification:
For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.
The priorities of the ranking methods are ordered as A
> C
> M
>E
. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.
If a student is not on the grading list, simply output N/A
.
Sample Input:
5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999
Sample Output:
1 C
1 M
1 E
1 A
3 A
N/A
题意:
输入学生 以及三门课的成绩,然后每输入一个学生的id就打印最高的排名和对应排名的分类。
排名分成三门课的单独排名和平均分的排名。
我的代码:
#include<bits/stdc++.h>
using namespace std;
class Stu{
public:Stu(){
};~Stu(){
};Stu(string name,int a,int c,int m,int e):id(name),s_a(a),s_c(c),s_m(m),s_e(e){
}string id;int s_a;int s_c;int s_m;int s_e;
};
int main()
{
int num_a[101]={
0};int num_c[101]={
0};int num_m[101]={
0};int num_e[101]={
0};string rank_kind="ACME";int N,M;cin>>N>>M;map<string,Stu>all_stu;for(int i=0;i<N;i++){
string name;int c,m,e;cin>>name>>c>>m>>e;int a=(c+m+e)/3;Stu t(name,a,c,m,e);all_stu[name]=t;num_a[a]++;num_c[c]++;num_m[m]++;num_e[e]++;}//算排名int sum_a=0;int sum_c=0;int sum_m=0;int sum_e=0;for(int i=100;i>=0;i--){
if(num_a[i]){
int t=num_a[i];num_a[i]=sum_a+1;sum_a+=t;}if(num_c[i]){
int t=num_c[i];num_c[i]=sum_c+1;sum_c+=t;}if(num_m[i]){
int t=num_m[i];num_m[i]=sum_m+1;sum_m+=t;}if(num_e[i]){
int t=num_e[i];num_e[i]=sum_e+1;sum_e+=t;}}for(int i=0;i<M;i++){
string name;cin>>name;if(all_stu.find(name)==all_stu.end())cout<<"N/A"<<endl;else{
int rank_t[4]={
0};rank_t[0]=num_a[all_stu[name].s_a];rank_t[1]=num_c[all_stu[name].s_c];rank_t[2]=num_m[all_stu[name].s_m];rank_t[3]=num_e[all_stu[name].s_e];int min_rank=100,min_rank_id;for(int j=0;j<=3;j++){
if(min_rank>rank_t[j]){
min_rank=rank_t[j];min_rank_id=j;}}cout<<min_rank<<" "<<rank_kind[min_rank_id]<<endl;}}return 0;
}
我的思路: 所有数组记录所有成绩有的人数,然后从100分往下算出每个成绩对应的排名。输入一个学生,查看他四个排名,然后输出排名和类型。