您的位置:首页 > 编程语言 > C语言/C++

【C++】1012. The Best Rank (25)

2014-03-19 12:36 411 查看

1012. The Best Rank (25)

时间限制
400 ms

内存限制
32000 kB

代码长度限制
16000 B

判题程序
Standard

作者
CHEN, Yue

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

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 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


aaaaaa .代码重复性有点高~
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;
//C7
struct grade{
int id;
int c;
int m;
int e;
int a;
};

vector<grade> b;

int cmp1(int aa,int bb){
return b[aa].c>b[bb].c;
}

int cmp2(int aa,int bb){
return b[aa].m>b[bb].m;
}

int cmp3(int aa,int bb){
return b[aa].e>b[bb].e;
}

int cmp4(int aa,int bb){
return b[aa].a>b[bb].a;
}

int a[5][1000000]={0};

int min(int aa){
int max=2001;
for(int i=1;i<5;i++){
if(max>a[i][aa]){
max=a[i][aa];
}
}
return max;

}

int main() {
int N,M;
freopen("in.txt","r",stdin);
while(scanf("%d%d",&N,&M)!=EOF){
vector<int> r;
vector<int>::iterator it;
while(N--){
grade c;
int id,cg,mg,eg;
scanf("%d%d%d%d",&c.id,&c.c,&c.m,&c.e);
c.a=c.c+c.m+c.e;
b.push_back(c);
a[0][c.id]=b.size()-1;
r.push_back(b.size()-1);
}
//C
sort(r.begin(),r.end(),cmp1);
int rr=1,gg=b[(*r.begin())].c;
a[1][b[(*r.begin())].id]=1;
for(it=r.begin()+1;it!=r.end();it++){
grade tt=b[(*it)];
if(tt.c==gg){
a[1][tt.id]=rr;
}else{
rr=it-r.begin()+1;
gg=tt.c;
a[1][tt.id]=rr;
}
}
//
sort(r.begin(),r.end(),cmp2);
rr=1;
gg=b[(*r.begin())].m;
a[2][b[(*r.begin())].id]=1;
for(it=r.begin()+1;it!=r.end();it++){
grade tt=b[(*it)];
if(tt.m==gg){
a[2][tt.id]=rr;
}else{
rr=it-r.begin()+1;
gg=tt.m;
a[2][tt.id]=rr;
}
}

//
sort(r.begin(),r.end(),cmp3);
rr=1;
gg=b[(*r.begin())].m;
a[3][b[(*r.begin())].id]=1;
for(it=r.begin()+1;it!=r.end();it++){
grade tt=b[(*it)];
if(tt.e!=gg){
rr=it-r.begin()+1;
gg=tt.e;
}
a[3][tt.id]=rr;
}
//
sort(r.begin(),r.end(),cmp4);
rr=1;
gg=b[(*r.begin())].a;
a[4][b[(*r.begin())].id]=1;
for(it=r.begin()+1;it!=r.end();it++){
grade tt=b[(*it)];
if(tt.a!=gg){
rr=it-r.begin()+1;
gg=tt.a;
}
a[4][tt.id]=rr;
}
while(M--){
int te;
scanf("%d",&te);
//cout<<a[4][te];
if(a[4][te]==0){
cout<<"N/A"<<endl;
}else{
int aa=min(te);
printf("%d ",aa);
if(a[4][te]==aa){
printf("A");
}else if(a[1][te]==aa){
printf("C");
}else if(a[2][te]==aa){
printf("M");
}else {
printf("E");
}
printf("\n");
}
}

}

//cout<<" aa";
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: