PAT乙级 1080.MOOC期终成绩

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
struct node
{
    string name;
    int grom;
    int Gm;
    int Gn;
    int G;
    bool gm;
    bool gn;
} note[10010];
bool cmp(struct node a,struct node b)
{
    if(a.G==b.G)
        return a.name<b.name;
    else
        return a.G>b.G;
}
int main()
{
    map<string,int> p2;
    set<string> p1;
    int p,m,n,t=0;
    cin>>p>>m>>n;
    for(int i=0;i<p;i++)
    {
        string s1;
        int z;
        cin>>s1;
        scanf("%d",&z);
        if(z>=200)
        {
            p1.insert(s1);
            note[t].name=s1;
            note[t].grom=z;
            p2[s1]=t;
            t++;
        }
    }
    for(int i=0;i<m;i++)
    {
        string s1;
        int z;
        cin>>s1;
        scanf("%d",&z);
        if(p1.count(s1))
        {
            note[p2[s1]].Gm=z;
            note[p2[s1]].gm=true;
        }
        else
            continue;
    }
    for(int i=0;i<t;i++)
    {
        if(!note[i].gm)
            note[i].Gm=-1;
    }
    for(int i=0;i<n;i++)
    {
        string s1;
        int z;
        cin>>s1;
        scanf("%d",&z);
        if(p1.count(s1))
        {
            note[p2[s1]].Gn=z;
            note[p2[s1]].gn=true;
        }
        else
            continue;
    }
    for(int i=0;i<t;i++)
    {
        if(!note[i].gn)
            note[i].Gn=-1;
    }
    for(int i=0;i<t;i++)
    {
        if(note[i].Gm>note[i].Gn)
            note[i].G=((0.40*note[i].Gm+0.60*note[i].Gn)*10+5)/10;
        else
            note[i].G=note[i].Gn;
    }
    sort(note,note+t,cmp);
    for(int i=0;i<t;i++)
    {
        if(note[i].G>=60)
        {
            cout<<note[i].name;
            printf(" %d ",note[i].grom);
            printf("%d ",note[i].Gm);
            printf("%d ",note[i].Gn);
            printf("%d\n",note[i].G);
        }
        else
            break;
    }
    return 0;
}

发布了45 篇原创文章 · 获赞 1 · 访问量 6788

猜你喜欢

转载自blog.csdn.net/Ls_attack/article/details/79797831