目录

​1,题目描述​

​题目大意​

​注意​

​2,思路​

​3,AC代码​

​4,解题过程​

​第一搏​

​第二搏​


1,题目描述

PAT_甲级_1137 Final Grading (25point(s)) (C++)【模拟/成绩排序】_模拟成绩排序

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

题目大意

 根据学生各个项目的分数排序,并对满足资格的同学给出获奖证书。

 

注意

  • G must be rounded up to an integer:G要四舍五入;
  • 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:编程成绩要大于等于200且最终成绩大于等于60,才有资格获得证书;
  • The final grade is calculated by G=(G​mid−term​​×40%+G​final​​×60%) if G​mid−term​​>G​final​​, or G​final​​ will be taken as the final grade G:期中成绩大于期末成绩时,按照权重计算最终成绩。否则取期末成绩作为最终成绩;

 

2,思路

接受每项的成绩,并在map中记录。遍历map将有资格的同学放入ans中,并对其排序。

 

3,AC代码

#include<bits/stdc++.h>
using namespace std;
struct node{
string name;
int Gp = -1, Gm = -1, Gf = -1, G = -1;//Gp:编程练习 Gm:期中成绩 Gf:期末成绩 G:最终成绩
};
bool cmp1(node a, node b){
return a.G != b.G ? a.G > b.G : a.name < b.name;
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
int P, M, N, score;
string name;
scanf("%d%d%d", &P, &M, &N);
unordered_map<string, node> data;
vector<node> ans;
for(int i = 0; i < P; i++){
cin>>name>>score;
data[name].name = name;
data[name].Gp = score;
}
for(int i = 0; i < M; i++){
cin>>name>>score;
data[name].Gm = score;
}
for(int i = 0; i < N; i++){
cin>>name>>score;
data[name].Gf = score;
data[name].G = data[name].Gm > data[name].Gf ? (data[name].Gm*0.4+data[name].Gf*0.6+0.5) : (data[name].Gf);
}
for(auto it : data){
if(it.second.Gp >= 200 && it.second.G >= 60)
ans.push_back(it.second);
}
sort(ans.begin(), ans.end(), cmp1);
for(auto it : ans){
cout<<it.name<<' ';
//printf("%d %d %d %d\n", it.Gp, it.Gm==0 ? -1 : it.Gm, it.Gf==0 ? -1 : it.Gf, it.G);
printf("%d %d %d %d\n", it.Gp, it.Gm, it.Gf, it.G);
}
return 0;
}

4,解题过程

第一搏

理解题意后,感觉不是很难的模拟题。

#include<bits/stdc++.h>
using namespace std;
struct node{
string name;
int Gp, Gm, Gf, G;//Gp:编程练习 Gm:期中成绩 Gf:期末成绩 G:最终成绩
};
bool cmp1(node a, node b){
if(a.G != b.G) return a.G > b.G;
else return a.name < b.name;
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE
int P, M, N, score;
string name;
scanf("%d%d%d", &P, &M, &N);
unordered_map<string, node> data;
vector<node> ans;
for(int i = 0; i < P; i++){
cin>>name>>score;
data[name].name = name;
data[name].Gp = score;
}
for(int i = 0; i < M; i++){
cin>>name>>score;
data[name].Gm = score;
}
for(int i = 0; i < N; i++){
cin>>name>>score;
data[name].Gf = score;
data[name].G = data[name].Gm > data[name].Gf ? (data[name].Gm*0.4+data[name].Gf*0.6+0.5) : (data[name].Gf);
}
for(auto it : data){
if(it.second.Gp >= 200 && it.second.G >= 60)
ans.push_back(it.second);
}
sort(ans.begin(), ans.end(), cmp1);
for(auto it : ans){
cout<<it.name<<' ';
printf("%d %d %d %d\n", it.Gp, it.Gm==0 ? -1 : it.Gm, it.Gf==0 ? -1 : it.Gf, it.G);
}
return 0;
}

PAT_甲级_1137 Final Grading (25point(s)) (C++)【模拟/成绩排序】_模拟成绩排序_02

第二搏

理论上应该是没有问题的,唯一可疑的地方就是初始化那块了。。。

于是我在结构体中直接将各个分数赋初值为-1:

PAT_甲级_1137 Final Grading (25point(s)) (C++)【模拟/成绩排序】_PAT_03

PAT_甲级_1137 Final Grading (25point(s)) (C++)【模拟/成绩排序】_模拟成绩排序_04

666,不管怎样以后一定要赋初值!这已经是第二次了。。。 

PAT_甲级_1137 Final Grading (25point(s)) (C++)【模拟/成绩排序】_甲级_05