solution
- 输出合格的学生信息,其中所谓合格需要同时满足
- 在线编程成绩>=200
- 总评成绩>=60
总评计算方法为- 当期中成绩>期末成绩时,总评=期中成绩0.4+期末成绩0.6
- 否则,总评=期末成绩
- 通过map建立学号和学生信息间的关联,否则直接顺序查找的话测试点3超时
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
const int maxn = 1e4 + 10;
struct stu{
string id;
double gp, gm = -1, gf = -1, f = 0;
friend bool operator < (stu &s1, stu &s2){
if(s1.f == s2.f) return s1.id < s2.id ;
return s1.f > s2.f;
}
}stus[maxn];
int main(){
int p, m, n, st, cnt = 0;
string t;
map<string, int> mp;
cin >> p >> m >> n;
while(p--){
cin >> t >> st;
if(st >= 200){
stus[cnt].id = t;
stus[cnt].gp = st;
mp[t] = cnt++;
}
}
while(m--){
cin >> t >> st;
if(mp.count(t)) stus[mp[t]].gm = st;
}
while(n--){
cin >> t >> st;
if(mp.count(t)) stus[mp[t]].gf = st;
}
for(int i = 0; i < cnt; i++){
if(stus[i].gm > stus[i].gf) stus[i].f = (int)(stus[i].gm * 0.4 + stus[i].gf * 0.6 + 0.5);
else stus[i].f = stus[i].gf;
}
sort(stus, stus + cnt);
for(int i = 0; i < cnt; i++){
if(stus[i].f >= 60) cout << stus[i].id << " " << stus[i].gp << " " << stus[i].gm << " " << stus[i].gf << " " << (int)(stus[i].f + 0.5) << endl;
}
return 0;
}