Source:
Description:
For a student taking the online course "Data Structures" on China University MOOC (http://www.icourse163.org/), to be qualified for a certificate, he/she must first obtain no less than 200 points from the online programming assignments, and then receive a final grade no less than 60 out of 100. The final grade is calculated by 0 if Gmid−term>Gfinal, or Gfinal will be taken as the final grade G. Here Gmid−term and Gfinal are the student's scores of the mid-term and the final exams, respectively.
The problem is that different exams have different grading sheets. Your job is to write a program to merge all the grading sheets into one.
Input Specification:
Each input file contains one test case. For each case, the first line gives three positive integers: P , the number of students having done the online programming assignments; M, the number of students on the mid-term list; and N, the number of students on the final exam list. All the numbers are no more than 10,000.
Then three blocks follow. The first block contains P online programming scores Gp's; the second one contains M mid-term scores Gmid−term's; and the last one contains N final exam scores Gfinal's. Each score occupies a line with the format:
StudentID Score
, whereStudentID
is a string of no more than 20 English letters and digits, andScore
is a nonnegative integer (the maximum score of the online programming is 900, and that of the mid-term and final exams is 100).
Output Specification:
For each case, print the list of students who are qualified for certificates. Each student occupies a line with the format:
StudentID
Gp Gmid−term Gfinal GIf some score does not exist, output "−" instead. The output must be sorted in descending order of their final grades (G must be rounded up to an integer). If there is a tie, output in ascending order of their
StudentID
's. It is guaranteed that theStudentID
's are all distinct, and there is at least one qullified student.
Sample Input:
6 6 7 01234 880 a1903 199 ydjh2 200 wehu8 300 dx86w 220 missing 400 ydhfu77 99 wehu8 55 ydjh2 98 dx86w 88 a1903 86 01234 39 ydhfu77 88 a1903 66 01234 58 wehu8 84 ydjh2 82 missing 99 dx86w 81
Sample Output:
missing 400 -1 99 99 ydjh2 200 98 82 88 dx86w 220 88 81 84 wehu8 300 55 84 84
Keys:
- 快乐模拟
- map(C++ STL)
- string(C++ STL)
Attention:
- 四舍五入要用round()函数;
- MAXSIZE最多有三倍的1E4;
- 从总分计算公式可以看出来,不参加期末考试,最多拿40分,是不会得到证书的
Code:
1 /*
2 Data: 2019-08-07 20:05:38
3 Problem: PAT_A1137#Final Grading
4 AC: 32:45
5
6 题目大意:
7 获得证书需要,编程任务不少于200分,总分不少于60分
8 如果期中>期末分数,则总分=期中*0.4+期末*0.6
9 反之,总分=期末分数
10 输入:
11 第一行给出,完成编程的人数P,参加期中考试的人数M,参加期末考试的人数N,均<=1e4
12 接下来给出各项分数;id不超过20位
13 */
14 #include<cstdio>
15 #include<string>
16 #include<map>
17 #include<cmath>
18 #include<vector>
19 #include<iostream>
20 #include<algorithm>
21 using namespace std;
22 const int M=1e4+10;
23 int pt=1;
24 struct node
25 {
26 string id;
27 int gp,gm,gf,g;
28 }info[M],temp;
29 map<string,int> mp;
30 vector<node> ans;
31
32 int Hash(string s)
33 {
34 if(mp[s]==0)
35 mp[s]=pt++;
36 return mp[s];
37 }
38
39 bool cmp(const node &a, const node &b)
40 {
41 if(a.g != b.g)
42 return a.g > b.g;
43 else
44 return a.id < b.id;
45 }
46
47 int main()
48 {
49 #ifdef ONLINE_JUDGE
50 #else
51 freopen("Test.txt", "r", stdin);
52 #endif // ONLINE_JUDGE
53
54 int n,m,p;
55 scanf("%d%d%d", &p,&m,&n);
56 for(int i=0; i<p; i++)
57 {
58 temp = node{"",-1,-1,-1,-1};
59 cin >> temp.id >> temp.gp;
60 if(temp.gp<200)
61 continue;
62 int pos = Hash(temp.id);
63 info[pos]=temp;
64 }
65 for(int i=0; i<m; i++)
66 {
67 cin >> temp.id >> temp.gm;
68 if(mp[temp.id]==0)
69 continue;
70 int pos = mp[temp.id];
71 info[pos].gm = temp.gm;
72 }
73 for(int i=0; i<n; i++)
74 {
75 cin >> temp.id >> temp.gf;
76 if(mp[temp.id]==0)
77 continue;
78 int pos = mp[temp.id];
79 info[pos].gf = temp.gf;
80 if(info[pos].gf >= info[pos].gm)
81 info[pos].g = info[pos].gf;
82 else
83 info[pos].g = (int)round((0.4)*info[pos].gm+(0.6)*info[pos].gf);
84 if(info[pos].g >= 60)
85 ans.push_back(info[pos]);
86 }
87 sort(ans.begin(),ans.end(),cmp);
88 for(int i=0; i<ans.size(); i++)
89 printf("%s %d %d %d %d\n", ans[i].id.c_str(),ans[i].gp,ans[i].gm,ans[i].gf,ans[i].g);
90
91 return 0;
92 }
/*Data: 2019-08-07 20:05:38Problem: PAT_A1137#Final GradingAC: 32:45
题目大意:获得证书需要,编程任务不少于200分,总分不少于60分如果期中>期末分数,则总分=期中*0.4+期末*0.6反之,总分=期末分数输入:第一行给出,完成编程的人数P,参加期中考试的人数M,参加期末考试的人数N,均<=1e4接下来给出各项分数;id不超过20位*/#include<cstdio>#include<string>#include<map>#include<cmath>#include<vector>#include<iostream>#include<algorithm>using namespace std;const int M=1e4+10;int pt=1;struct node{ string id; int gp,gm,gf,g;}info[M],temp;map<string,int> mp;vector<node> ans;
int Hash(string s){ if(mp[s]==0) mp[s]=pt++; return mp[s];}
bool cmp(const node &a, const node &b){ if(a.g != b.g) return a.g > b.g; else return a.id < b.id;}
int main(){#ifdef ONLINE_JUDGE#else freopen("Test.txt", "r", stdin);#endif // ONLINE_JUDGE
int n,m,p; scanf("%d%d%d", &p,&m,&n); for(int i=0; i<p; i++) { temp = node{"",-1,-1,-1,-1}; cin >> temp.id >> temp.gp; if(temp.gp<200) continue; int pos = Hash(temp.id); info[pos]=temp; } for(int i=0; i<m; i++) { cin >> temp.id >> temp.gm; if(mp[temp.id]==0) continue; int pos = mp[temp.id]; info[pos].gm = temp.gm; } for(int i=0; i<n; i++) { cin >> temp.id >> temp.gf; if(mp[temp.id]==0) continue; int pos = mp[temp.id]; info[pos].gf = temp.gf; if(info[pos].gf >= info[pos].gm) info[pos].g = info[pos].gf; else info[pos].g = (int)round((0.4)*info[pos].gm+(0.6)*info[pos].gf); if(info[pos].g >= 60) ans.push_back(info[pos]); } sort(ans.begin(),ans.end(),cmp); for(int i=0; i<ans.size(); i++) printf("%s %d %d %d %d\n", ans[i].id.c_str(),ans[i].gp,ans[i].gm,ans[i].gf,ans[i].g);
return 0;}
来源:oschina
链接:https://my.oschina.net/u/4274516/blog/3522218