复习
结构体
struct student{ //定义
string a;
int b;
};
bool my(student a,student b){ //自定义排序
if(a.int == b.int) return a.string < b.string;
else return a.int > b.int
}
sort(stu,stu+n,my);
map
map<string,string> a;
map<string,string>:iterator it; //遍历
for(it = a.begin(); it != a.end(); it++){
it -> second;
}
一开始直接用循环,超时,存储检查改用了map,不超时但是最后一个点报错,搞不懂,,理论都是对的,,
残缺代码
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
struct student{
string name;
double gp = 0;
double gm = 0;
double gfin = 0;
double g = 0;
};
bool my(student a, student b){
if(a.g == b.g) return a.name < b.name;
return a.g > b.g;
}
int p,m,n;
student stu[110000];
int main(){
cin >> p >> m >> n;
map<string,student> t;
for(int i=0; i<p; i++){
string a;
double b;
cin >> a >> b;
if(b >= 0 && b <= 900){
t[a].name = a;
t[a].gp = b;
}
}
for(int i=0; i<m; i++){
string a;
double b;
cin >> a >> b;
if(b >= 0 && b <= 100){
t[a].name = a;
t[a].gm = b;
}
}
for(int i=0; i<n; i++){
string a;
double b;
cin >> a >> b;
if(b >= 0 && b <= 100){
t[a].name = a;
t[a].gfin = b;
}
}
map<string,student>::iterator it;
int key = 0;
for(it = t.begin(); it != t.end(); it++){
stu[key] = it -> second;
if(stu[key].gm > stu[key].gfin){
stu[key].g = stu[key].gm * 0.4 + stu[key].gfin * 0.6;
if(stu[key].g - (int)stu[key].g < 0.5)
stu[key].g = (int)stu[key].g;
else stu[key].g = (int)stu[key].g + 1 ;
}
else
stu[key].g = stu[key].gfin;
key = key + 1;
}
sort(stu,stu+key,my);
for(int i=0; i<key; i++){
if(stu[i].g >= 60 && stu[i].gp >= 200 && stu[i].gfin != 0){
if(stu[i].gm == 0) stu[i].gm = -1;
cout << stu[i].name << " " << stu[i].gp << " ";
cout << stu[i].gm << " " << stu[i].gfin << " ";
cout << stu[i].g << endl;
}
}
return 0;
}