PAT甲級-1012. The Best Rank (25)並列排序
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 Algebra), 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
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
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 Input5 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 999999Sample Output
1 C 1 M 1 E 1 A 3 A N/A
給出N個學生的ID及其程式設計、數學、英語的分數,計算其平均分,排序後根據給定ID查詢得出學生的各科成績中排名最好的單科成績,輸出排名及科目名稱。
注意排名含有相同分數並列的情況時,採取名次並列,後繼遞減的方法,例如第一第二並列第一時,第三名還是第三,即 1 1 3 4。
#include<bits/stdc++.h>
using namespace std;
#define INF 0xfffffff
#define MAXN 2010
struct N
{
string id;
double ave,c,m,e;
int no,na,nc,nm,ne;//最好排名,均分排名,程式設計排名,數學排名,英語排名
char sub;//排名最好的科目的名稱
} a[MAXN];
bool cmp1(N x,N y)//按均分排
{
return x.ave>y.ave;
}
bool cmp2(N x,N y)//按程式設計分排
{
return x.c>y.c;
}
bool cmp3(N x,N y)//按數學分排
{
return x.m>y.m;
}
bool cmp4(N x,N y)//按英語分排
{
return x.e>y.e;
}
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("F:/cb/read.txt","r",stdin);
//freopen("F:/cb/out.txt","w",stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int n,q;
cin>>n>>q;
for(int i=0; i<n; ++i)
{
cin>>a[i].id>>a[i].c>>a[i].m>>a[i].e;
a[i].ave=(a[i].c+a[i].m+a[i].e)/3.0;
}
bool flag=false;
int no=INF;
sort(a,a+n,cmp1);
int cnt=0;//記錄相同分數的學生人數
a[0].na=cnt;
for(int i=1; i<n; ++i)
{
if(a[i].ave==a[i-1].ave) ++cnt;//篩重
else cnt=0;
a[i].na=i-cnt;
}
sort(a,a+n,cmp2);
cnt=0;
a[0].nc=cnt;
for(int i=1; i<n; ++i)
{
if(a[i].c==a[i-1].c) ++cnt;
else cnt=0;
a[i].nc=i-cnt;
}
sort(a,a+n,cmp3);
cnt=0;
a[0].nm=cnt;
for(int i=1; i<n; ++i)
{
if(a[i].m==a[i-1].m) ++cnt;
else cnt=0;
a[i].nm=i-cnt;
}
sort(a,a+n,cmp4);
cnt=0;
a[0].ne=cnt;
for(int i=1; i<n; ++i)
{
if(a[i].e==a[i-1].e) ++cnt;
else cnt=0;
a[i].ne=i-cnt;
}
for(int i=0; i<n; ++i)//從各科排名中選出最好排名
{
if(a[i].na<=a[i].nc&&a[i].na<=a[i].nm&&a[i].na<=a[i].ne) a[i].no=a[i].na,a[i].sub='A';
else if(a[i].nc<=a[i].na&&a[i].nc<=a[i].nm&&a[i].nc<=a[i].ne) a[i].no=a[i].nc,a[i].sub='C';
else if(a[i].nm<=a[i].nc&&a[i].nm<=a[i].na&&a[i].nm<=a[i].ne) a[i].no=a[i].nm,a[i].sub='M';
else if(a[i].ne<=a[i].nc&&a[i].ne<=a[i].nm&&a[i].ne<=a[i].na) a[i].no=a[i].ne,a[i].sub='E';
}
for(int i=0; i<q; ++i)
{
string s;
cin>>s;
flag=false;
for(int j=0; j<n; ++j)
if(s==a[j].id)
{
flag=true;
no=j;
break;
}
if(flag) cout<<++a[no].no<<" "<<a[no].sub<<endl;
else cout<<"N/A"<<endl;
}
}
相關文章
- PAT甲級-1010. Radix (25)進位制
- PAT甲級1154 Vertex Coloring (25分)|C++實現C++
- PAT甲級1122 Hamiltonian Cycle (25分)|C++實現C++
- PAT甲級1110 Complete Binary Tree (25分)|C++實現C++
- PAT甲級1023 Have Fun with Number
- PAT 甲級 1152 Google Recruitment (20分)GoUI
- PAT甲級考試題庫題目分類
- PAT乙級——1092(陣列排序 自定義sort)Java實現陣列排序Java
- 【PAT甲級A1038】Recover the Smallest Number (30分)(c++)C++
- PAT甲級-1005. Spell It Right (20)各位之和
- 【PAT甲級A1084】Broken Keyboard (20分)(c++)C++
- PAT甲級1126~1130|C++實現C++
- 2024 秋季PAT認證甲級(題解A1-A4)
- PAT甲級-1014. Waiting in Line (30)(模擬)AI
- 2021.9.12週六PAT甲級考試覆盤與總結
- 【PAT甲級A1065】A+B and C (64bit) (20分)(c++)C++
- R排序sort、order、rank、arrange排序
- 分析函式——排序排列(rank、dense_rank、row_number)函式排序
- SQL SERVER 排序函式ROW_NUMBER、RANK、DENSE_RANK、NTILESQLServer排序函式
- 25 Best Java Books In 2022Java
- (非原創)PAT甲級1123 Is It a Complete AVL Tree (30分)|C++實現C++
- 菜鳥記錄:c語言實現PAT甲級1010--RadixC語言
- HDU 5131 Song Jiang's rank list(排序)排序
- [PAT]1028. List Sorting (25)@Java實現Java
- mysql自動排序函式dense_rank() over()、rank() over()、row_num() over()用法和區別MySql排序函式
- PAT-B 1015 德才論【排序】排序
- 層級查詢並將層級拆分成多列
- 並查集系列之「基於rank的優化」並查集優化
- 【PAT乙級】1048 數字加密加密
- rank() 與dense_rank()分析
- PAT-B 1060 愛丁頓數【排序】排序
- pat—結構體排序(用map彌補struct缺陷)結構體排序Struct
- rank
- 並查集系列之「基於rank的最佳化」並查集
- 分析函式DENSE_RANK 和 RANK函式
- PAT (Advanced Level) Practice 1149 Dangerous Goods Packaging (25分)Go
- 陣列排序陣列排序
- 1012. 變換密碼密碼