zoukankan      html  css  js  c++  java
  • PAT1137 Final Grading

    链接https://pintia.cn/problem-sets/994805342720868352/problems/994805345401028608

    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 = (G~mid-term~x 40% + G~final~x 60%) if G~mid-term~ > G~final~, or G~final~ will be taken as the final grade G. Here G~mid-term~ and G~final~ 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 G~p~'s; the second one contains M mid-term scores G~mid-term~'s; and the last one contains N final exam scores G~final~'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 G~p~ G~mid-term~ G~final~ G

    If 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 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

    几个概念需要理清,即final grade 和final grade G。前者是最后的总成绩,后者是期末考试的成绩。最后要求是总成绩不小于60
    #include<cstdio>
    #include<cmath>
    #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<string>
    #include<map>
    #include<cstring>
    #define DEBUG(x) cout << #x << " = " << x << endl
    using namespace std;
    struct student{
        int nId;
        string Id;
        int online,middle,last,total;
        student(){
            online=-1;
            middle=-1;
            last=-1;
            total=-1;
        }
        void calculate(){
            if(middle>last)total=middle*0.4+last*0.6+0.5;
            else total=last;
        }
        void Print(){
            cout<<Id<<" ";
            cout<<online<<" "<<middle<<" "<<last<<" "<<total<<endl;
        }
        bool operator<(const student &s)const{
            if(total!=s.total)return total>s.total;
            else {
                return Id<s.Id;
            }
        }
    };
    int ptr=0;
    map<string,int>num;
    map<int,string>id;
    int P,M,N;
    vector<student>v;
    int main()
    {
    //    freopen("in.txt","r",stdin);
        scanf("%d%d%d",&P,&M,&N);
        for(int i=0;i<P;i++){
            student st;
            cin>>st.Id>>st.online;
            if(st.online>=200) {
                if(num.find(st.Id)==num.end()) {
                    num[st.Id]=ptr;
                    id[ptr]=st.Id;
                    st.nId=ptr;
                    v.push_back(st);
                    ptr++;
                } else {
                    int i=num[st.Id];
                    v[i].online=max(v[i].online,st.online);
                }
            }
        }
        for(int i=0;i<M;i++){
            string s;
            int m;
            cin>>s>>m;
            if(num.find(s)!=num.end()){
                int id=num[s];
                v[id].middle=max(v[id].middle,m);
            }
        }
        for(int i=0;i<N;i++){
            string s;
            int m;
            cin>>s>>m;
            if(num.find(s)!=num.end()){
                int id=num[s];
                v[id].last=max(v[id].last,m);
                v[id].calculate();
            }
        }
        sort(v.begin(),v.end());
        for(int i=0;i<v.size();i++){
                if(v[i].total>=60)
                v[i].Print();
        }
        return 0;
    }
     
  • 相关阅读:
    带横线圆圈标题
    锚点点击导航 跳转到相应位置,样式随之变化
    导航随滚动改变样式
    for循环中嵌套函数,执行顺序和结果该如何理解?
    mui 记录
    获取页面所有a标签href
    cookie记录横向滚动条位置
    Istio全景监控与拓扑
    Istio 流量治理功能原理与实战
    Cloud Native Weekly | KubeCon首登中国,华为云亮相KubeCon 2018,微软云服务又罢工
  • 原文地址:https://www.cnblogs.com/MalcolmMeng/p/9187106.html
Copyright © 2011-2022 走看看