PAT甲级 1012 The Best Rank(25) (模拟)

编程入门 行业动态 更新时间:2024-10-24 01:57:59

<a href=https://www.elefans.com/category/jswz/34/1769282.html style=PAT甲级 1012 The Best Rank(25) (模拟)"/>

PAT甲级 1012 The Best Rank(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 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 CME 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.

输入

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 CM and E. Then there are M lines, each containing a student ID.

输出

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.

样例输入 

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

样例输出 

1 C
1 M
1 E
1 A
3 A
N/A

题意理解

题意是输入n个学生id,m个询问,然后输入三门成绩,第四门成绩是前三门成绩的一个平均值,在这里最好都使用double来存,因为可能会有平均值向下取整的情况,用int的话。m个询问id,如果此次询问不在学生库里面,那么输出一个N/A,否则输出的是一个该学生四门课最好的成绩排名,值得注意的是分数如果并列的话那么排名也并列,比如某科同学门成绩是

100 98 95 95 94  那么成绩排名就是 1 2 3 3 5  还有就是如果最好的排名一样 那么按照ACME的优先级输出各门课

代码 

#include<bits/stdc++.h> 
using namespace std;
typedef long long LL;
typedef unsigned long long ULL ;
typedef pair<int,int> PII;
#define fx first
#define fy second
const int INF =0x3f3f3f3f;
const int N=2e4+10;
const int MOD=1e9+7;
int n,m;
map<int,int>ma;//学生 
vector<double>C,M,E,A;
bool cmp(double a,double b){return a>b;
}
typedef struct person{int id;double c,m,e,a;int rankc,rankm,ranke,ranka;
}person;
person num[N];
void init(){sort(C.begin(),C.end(),cmp);sort(M.begin(),M.end(),cmp);sort(E.begin(),E.end(),cmp);sort(A.begin(),A.end(),cmp);for(int i=1;i<=n;i++){double c=num[i].c;for(int j=0;j<C.size();j++){if(c==C[j]){num[i].rankc=j+1;break;}}double m=num[i].m;for(int j=0;j<M.size();j++){if(m==M[j]){num[i].rankm=j+1;break;}}double e=num[i].e;for(int j=0;j<E.size();j++){if(e==E[j]){num[i].ranke=j+1;break;}}double a=num[i].a;for(int j=0;j<A.size();j++){if(a==A[j]){num[i].ranka=j+1;break;}}}
} 
void pr(person &res){int a=res.ranka,c=res.rankc,m=res.rankm,e=res.ranke;map<int,char>ans;map<int,char>::iterator it;ans[e]='E',ans[m]='M',ans[c]='C',ans[a]='A';printf("%d %c\n",ans.begin()->first,ans.begin()->second);
}
void solve(){scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){int id;double c,m,e;scanf("%d%lf%lf%lf",&id,&c,&m,&e);double av=(c+m+e)/3;num[i]={id,c,m,e,av}; C.push_back(c);M.push_back(m);E.push_back(e);A.push_back(av);ma[id]=i;//出现过 存下此id的结构体下标 }init();for(int i=1;i<=m;i++){int id;scanf("%d",&id);if(!ma[id])puts("N/A");else {int pos=ma[id];//此id在结构体中位置pr(num[pos]);}}
}
int main(){int T=1;
//    scanf("%d",&T);while(T--){solve();}return 0;
}

更多推荐

PAT甲级 1012 The Best Rank(25) (模拟)

本文发布于:2024-03-10 14:42:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1728253.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PAT   Rank

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!