For a student taking the online course “Data Structures” on China University MOOC (http://www.icourse163.org/), to be qualified for a certificate, 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. The final grade is calculated by G=(Gmid−term×40%+Gfinal×60%) if Gmid−term>Gfinal, or Gfinal will be taken as the final grade G. Here Gmid−term and Gfinal are the student’s scores of the mid-term and the final exams, respectively.
The problem is that different exams have different grading sheets. Your job is to write a program to merge all the grading sheets into one.
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
#include<iostream>
#include<cstring>
#include<unordered_map>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
struct Student
{
string id;
int p=-1,m=-1,f=-1,s=0;
};
bool cmp(Student a,Student b )
{
if(a.s!=b.s) return a.s>b.s;
else return a.id<b.id;
}
void calc(Student &a)
{
if(a.f>=a.m) a.s=a.f;
else a.s=round(a.m*0.4+a.f*0.6);
}
int main()
{
int p,m,n;
cin>>p>>m>>n;
unordered_map<string,Student> hash;
string id;
int s;
for(int i=0;i<p;i++)
{
cin>>id>>s;
hash[id].id=id;
hash[id].p=s;
}
for(int i=0;i<m;i++)
{
cin>>id>>s;
hash[id].id=id;
hash[id].m=s;
}
for(int i=0;i<n;i++)
{
cin>>id>>s;
hash[id].id=id;
hash[id].f=s;
}
vector<Student> students;
for(auto item:hash)
{
auto stu=item.second;
calc(stu);
if(stu.p>=200&&stu.s>=60)
students.push_back(stu);
}
sort(students.begin(),students.end(),cmp);
for(auto s:students)
cout<<s.id<<' '<<s.p<<' '<<s.m<<' '<<s.f<<' '<<s.s<<endl;
return 0;
}