PAT 甲级 1137. Final Grading (25)(排序)

来源:互联网 发布:仿新浪微博源码 php 编辑:程序博客网 时间:2024/05/29 12:16
1137. Final Grading (25)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-termx 40% + Gfinalx 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.Input Specification:Each input file contains one test case. For each case, the first line gives three positive integers: P , the number of students having done the online programming assignments; M, the number of students on the mid-term list; and N, the number of students on the final exam list. All the numbers are no more than 10,000.Then three blocks follow. The first block contains P online programming scores Gp's; the second one contains M mid-term scores Gmid-term's; and the last one contains N final exam scores Gfinal's. Each score occupies a line with the format: StudentID Score, where StudentID is a string of no more than 20 English letters and digits, and Score is a nonnegative integer (the maximum score of the online programming is 900, and that of the mid-term and final exams is 100).Output Specification:For each case, print the list of students who are qualified for certificates. Each student occupies a line with the format:StudentID Gp Gmid-term Gfinal GIf some score does not exist, output "-1" instead. The output must be sorted in descending order of their final grades (G must be rounded up to an integer). If there is a tie, output in ascending order of their StudentID's. It is guaranteed that the StudentID's are all distinct, and there is at least one qualified student.Sample Input:6 6 701234 880a1903 199ydjh2 200wehu8 300dx86w 220missing 400ydhfu77 99wehu8 55ydjh2 98dx86w 88a1903 8601234 39ydhfu77 88a1903 6601234 58wehu8 84ydjh2 82missing 99dx86w 81Sample Output:missing 400 -1 99 99ydjh2 200 98 82 88dx86w 220 88 81 84wehu8 300 55 84 84
依次给出在线课程成绩,期中成绩,期末成绩,录取要求为课堂成绩必须不低于200,最终成绩不低于60,最终成绩计算法则:如果期中成绩大于期末成绩,最终成绩=期中成绩*0.4+期末成绩*0.6,结果四舍五入。否则直接用期末成绩代替。
#include <iostream>#include <vector>#include <algorithm> #include <map>using namespace std;struct Student{    string name;    int Go=-1, Gm=-1, Gf=-1, G=-1;}stu[10010];bool cmp1(Student s1, Student s2){    if (s1.Gf != s2.Gf) return s1.G > s2.G;    return s1.name < s2.name;}vector<Student> v;map<string, int> book;int p, m, n, score;string name;int main(){      freopen("input.txt", "r", stdin);    scanf("%d%d%d", &p, &n, &m);    for (int i = 1; i <= p; i++) {        cin>>name>>score;        stu[i].name = name;        stu[i].Go = score;        book[name] = i;    }    for (int i = 1; i <= m; i++) {        cin>>name>>score;        int id = book[name];        if (id == 0) continue;        stu[id].Gm = score;    }    for (int i = 1; i <= n; i++) {        cin>>name>>score;        int id = book[name];        if (id == 0) continue ;        stu[id].Gf = score;    }    for (int i = 1; i <= p; i++) {        if (stu[i].Go < 200) continue;        if (stu[i].Gm > stu[i].Gf) {            stu[i].G = (stu[i].Gm * 0.4 + stu[i].Gf * 0.6) + 0.5;        } else {            stu[i].G = stu[i].Gf;        }        if (stu[i].G >= 60) {            v.push_back(stu[i]);        }    }    sort(v.begin(), v.end(), cmp1);    for (int i = 0; i < v.size(); i++) {         printf("%s %d %d %d %d\n", v[i].name.c_str(), v[i].Go, v[i].Gm, v[i].Gf, v[i].G);    }    return 0;  }
原创粉丝点击