Skip to content

Commit 0075cb9

Browse files
committed
pat
1 parent f4b90fe commit 0075cb9

File tree

2 files changed

+91
-37
lines changed

2 files changed

+91
-37
lines changed

PAT/PAT_A/pat1012.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
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.
3+
4+
For example, The grades of C, M, E and A - Average of 4 students are given as the following:
5+
6+
StudentID C M E A
7+
310101 98 85 88 90
8+
310102 70 95 88 84
9+
310103 82 87 94 88
10+
310104 91 91 91 91
11+
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.
12+
13+
Input
14+
15+
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.
16+
17+
Output
18+
19+
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.
20+
21+
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.
22+
23+
If a student is not on the grading list, simply output "N/A".
24+
25+
Sample Input
26+
5 6
27+
310101 98 85 88
28+
310102 70 95 88
29+
310103 82 87 94
30+
310104 91 91 91
31+
310105 85 90 90
32+
310101
33+
310102
34+
310103
35+
310104
36+
310105
37+
999999
38+
Sample Output
39+
1 C
40+
1 M
41+
1 E
42+
1 A
43+
3 A
44+
N/A
45+
*/
46+
47+
#include <unordered_map>
48+
#include <vector>
49+
#include <algorithm>
50+
#include <string>
51+
#include <iostream>
52+
#include <unordered_set>
53+
54+
using namespace std;
55+
56+
int main()
57+
{
58+
unordered_set<string> um[4][101];
59+
int n, m;
60+
cin >> n >> m;
61+
for (int i=0; i<n; ++i) {
62+
string str;
63+
int c, m, e, a;
64+
cin >> str >> c >> m >> e;
65+
a = (c+m+e)/3;
66+
um[0][a].insert(str);
67+
um[1][c].insert(str);
68+
um[2][m].insert(str);
69+
um[3][e].insert(str);
70+
}
71+
unordered_map<string, pair<int, int>> res;
72+
for (int i=0; i<4; ++i) {
73+
int cnt = 0;
74+
for (int j=100; j>=0; --j) {
75+
for (auto & s: um[i][j])
76+
if (res.find(s) == res.end()
77+
|| res[s].first > cnt)
78+
res[s] = make_pair(cnt, i);
79+
cnt += um[i][j].size();
80+
}
81+
}
82+
while (m--) {
83+
string q;
84+
cin >> q;
85+
if (res.find(q) == res.end())
86+
cout << "N/A" << endl;
87+
else
88+
cout << res[q].first+1 << " " << "ACME"[res[q].second] << endl;
89+
}
90+
return 0;
91+
}

PAT/PAT_A/pat1012.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)