struct mooc{
string name;
int ol, mid, final, total;
};
bool cmp(mooc x,mooc y){
return x.total != y.total ? x.total > y.total : x.name < y.name;
/*if (x.total != y.total) return x.final > y.total;
else return x.name < y.name;*//这么写测试点3错误
}
//排序场景
vector<mooc> v
sort(v.begin(),v.end(),cmp);
搞不明白为什么测试点3的大数目排序注释里的写法就错了.
全代码
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
struct mooc{
string name;
int ol, mid, final, total;
};
bool cmp(mooc x,mooc y){
return x.total != y.total ? x.total > y.total : x.name < y.name;
/*if ( x.total != y.total) return x.final > y.total;
else return x.name < y.name;//字典序是<*///这么写测试点3错误,可能是大量数据的不稳定排序错误
}
map<string, int> order;//记录学生对应的合法插入序号
int main(){
int p, m, n, temp, cnt = 1;
string s;
cin >> p >> m >> n;
vector<mooc> v,ans;
for(int i = 0; i < p; i++){
cin >> s >> temp;
if (temp >= 200){
v.push_back(mooc{s, temp, -1, -1, 0});//有输入了先把其他-1占了
order[s] = cnt++;//说明有合法插入,记下顺序
}
}
for(int i = 0; i < m; i++){
cin >> s >> temp;
if (order[s] != 0)//如果!=0说明有合法ol成绩,没有就跳过
v[order[s] - 1].mid = temp;//有合法成绩,那么记录的序号-1就是在vector里的下标
}
for(int i=0;i<n;i++){
cin >> s >> temp;
if (order[s] != 0){//如果!=0说明有合法ol成绩,没有就跳过
v[order[s] - 1].total = v[order[s] - 1].final = temp;//有合法成绩,那么记录的序号-1就是在vector里的下标
if(v[order[s] - 1].mid > temp)//期中和期末比较,放在后面就是默认了一种情况,少写else
v[order[s] - 1].total = int( v[order[s] - 1].mid * 0.4 + v[order[s] - 1].final * 0.6 + 0.5);
//+0.5实现四舍五入,不加只保留整数
}
}
sort(v.begin(),v.end(),cmp);
for(int i=0;i<v.size();i++)
if (v[i].total >= 60)
printf("%s %d %d %d %d\n",v[i].name.c_str(),v[i].ol,v[i].mid,v[i].final,v[i].total);
return 0;
}