写在前面
- 思路分析
- 所有⼈必须要G编程>=200分,v数组保存G编程>=200的⼈
- 初始化gm和gf为-1
v.push_back(node{s, score, -1, -1, 0});
,map映射保存名字对应v中的下标 - G期中出现名字,如果对应map不存在(==0),学⽣编程成绩不满⾜条件,无须保存
- 更新存在的⼈期中考试成绩
- G期末出现且在map中存在的名字
- 先更新G期末和G总为新成绩
- 当G期末<G期中,将G总更更新为(G期中x 40% + G期末x 60%)
- 将v中所有G总满⾜条件的放⼊ans数组,ans排序(总分递减,总分相同则姓名递增)
- 输出ans中的学⽣生信息
- 题目简单,细节处理耗费时间,不再赘述
测试用例
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
output:
missing 400 -1 99 99
ydjh2 200 98 82 88
dx86w 220 88 81 84
wehu8 300 55 84 84
ac代码
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>
using namespace std;
struct node
{
string name;
int gp, gm, gf, g;
};
bool cmp(node a, node b)
{
return a.g != b.g ? a.g > b.g : a.name < b.name;
}
map<string, int> idx;
int main()
{
int p, m, n, score, cnt = 1;
cin >> p >> m >> n;
vector<node> v;
string s;
for (int i = 0; i < p; i++)
{
cin >> s >> score;
if (score >= 200)
{
v.push_back(node{s, score, -1, -1, 0});
idx[s] = cnt++;
}
}
for (int i = 0; i < m; i++)
{
cin >> s >> score;
if (idx[s] != 0) v[idx[s] - 1].gm = score;
}
for (int i = 0; i < n; i++)
{
cin >> s >> score;
if (idx[s] != 0)
{
int tmp = idx[s] - 1;
v[tmp].gf = v[tmp].g = score;
if (v[tmp].gm > v[tmp].gf) v[tmp].g = int(v[tmp].gm * 0.4 + v[tmp].gf * 0.6 + 0.5);
}
}
vector<node> ans;
for (int i = 0; i < v.size(); i++)
if (v[i].g >= 60) ans.push_back(v[i]);
sort(ans.begin(), ans.end(), cmp);
for (int i = 0; i < ans.size(); i++)
printf("%s %d %d %d %d\n", ans[i].name.c_str(), ans[i].gp, ans[i].gm, ans[i].gf, ans[i].g);
return 0;
}