-
Notifications
You must be signed in to change notification settings - Fork 0
/
1012_The_Best_Rank
181 lines (161 loc) · 5.2 KB
/
1012_The_Best_Rank
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
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
----------------------------------------------------------------------------------------------------------------
解:考到排序,用C++里的sort很方便啦,貌似我写得好啰嗦啊
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
struct student_rank
{
string id;
int c_score;
int m_score;
int e_score;
int a_score;
int c_rank;
int m_rank;
int e_rank;
int a_rank;
};
int n, m;
vector<student_rank> info;
vector<int> all_c, all_m, all_e, all_a;
void find_rank(int index)
{
for (int i = 0; i < n; ++i)
if(info[index].c_score == all_c[i]){
info[index].c_rank = i + 1;
break;
}
for (int i = 0; i < n; ++i)
if(info[index].m_score == all_m[i]){
info[index].m_rank = i + 1;
break;
}
for (int i = 0; i < n; ++i)
if(info[index].e_score == all_e[i]){
info[index].e_rank = i + 1;
break;
}
for (int i = 0; i < n; ++i)
if(info[index].a_score == all_a[i]){
info[index].a_rank = i + 1;
break;
}
}
bool comp(int i, int j){ return (i > j); }
int min(int a, int b, int c, int d)
{
int m = a < b ? a : b;
int n = c < d ? c : d;
return m < n ? m : n;
}
int main()
{
cin >> n >> m;
vector<string> search_id(m, "");
info = vector<student_rank>(n);
for (int i = 0; i < n; ++i)
{
cin >> info[i].id >> info[i].c_score >> info[i].m_score >> info[i].e_score;
float tmp =(float) (info[i].c_score + info[i].m_score + info[i].e_score);
info[i].a_score =floor(tmp / 3 + 0.5);
}
for(int i = 0; i < m; ++i)
cin >> search_id[i];
for(int i = 0; i < n; ++i)
{
all_c.push_back(info[i].c_score);
all_m.push_back(info[i].m_score);
all_e.push_back(info[i].e_score);
all_a.push_back(info[i].a_score);
}
sort(all_a.begin(), all_a.end(), comp);
sort(all_c.begin(), all_c.end(), comp);
sort(all_e.begin(), all_e.end(), comp);
sort(all_m.begin(), all_m.end(), comp);
for(int i = 0; i < n; ++i)
find_rank(i);
int i,j;
for(i = 0; i < m; ++i)
{
for(j = 0; j < n; ++j)
{
if(search_id[i] == info[j].id)
{
int best_rank = min(info[j].c_rank, info[j].m_rank, info[j].e_rank, info[j].a_rank);
if(info[j].a_rank == best_rank)
{
cout << info[j].a_rank << ' ' << 'A' << endl;
break;
}
if(info[j].c_rank == best_rank)
{
cout << info[j].c_rank << ' ' << 'C' << endl;
break;
}
if (info[j].m_rank == best_rank)
{
cout << info[j].m_rank << ' ' << 'M' << endl;
break;
}
if(info[j].e_rank == best_rank)
{
cout << info[j].e_rank << ' ' << 'E' << endl;
break;
}
}
else
continue;
}
if(j == n)
cout << "N/A" << endl;
}
return 0;
}