PAT_1075. PAT Judge

//
//  main.cpp
//  PAT_1075. PAT Judge
//
//  Created by wjq on 17/8/20.
//  Copyright © 2017年 wjq. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
map<int,int> m;
int score[10],submit[100005];
struct Player
{
    int id,get[10],perfectNum,canBeOutput;
}player[10005];
int idx=0;
bool hasSubmit[10005];
void init()
{
    for(int i=0;i<10005;i++)
    {
        for(int j=0;j<10;j++)
            player[i].get[j]=-2;
        player[i].perfectNum=0;
        player[i].canBeOutput=0;
    }
}
int cmp(Player a, Player b)
{
    if(a.get[0]==b.get[0])
    {
        if(a.perfectNum==b.perfectNum)
            return a.id<b.id;
        return a.perfectNum>b.perfectNum;
    }
    return a.get[0]>b.get[0];
}
int main(int argc, const char * argv[]) {
    init();
    int N,K,M,a,b,c;
    scanf("%d%d%d",&N,&K,&M);
    for(int i=1;i<=K;i++)
        scanf("%d",&score[i]);
    for(int i=0;i<M;i++)
    {
        scanf("%d%d%d",&a,&b,&c);
        if(hasSubmit[a]==false)
        {
            player[idx].id=a;
            m[a]=idx;
            player[idx].get[b]=c;
            hasSubmit[a]=true;
            idx++;
        }
        else
        {
            if(player[m[a]].get[b]==-2||c>player[m[a]].get[b])
                player[m[a]].get[b]=c;
        }
    }
    for(int i=0;i<idx;i++)
    {
        int sum=0,canBeOutput=0;
        for(int j=1;j<=K;j++)
        {
            if(player[i].get[j]>=0)
            {
                canBeOutput=1;
                sum+=player[i].get[j];
            }
            if(player[i].get[j]==score[j])
                player[i].perfectNum++;
            if(player[i].get[j]==-1)
                player[i].get[j]=0;
        }
        player[i].canBeOutput=canBeOutput;
        player[i].get[0]=sum;
    }
    sort(player,player+idx,cmp);
    
    int rank=1;
    for(int i=0;i<idx;i++)
    {
        if(player[i].canBeOutput==1)
        {
            if(player[i].get[0]!=player[i-1].get[0]&&i!=0)
                rank=i+1;
            printf("%d %05d %d",rank,player[i].id,player[i].get[0]);
            for(int j=1;j<=K;j++)
                if(player[i].get[j]!=-2)
                    printf(" %d",player[i].get[j]);
                else
                    printf(" -");
            printf("\n");
        }
    }
    return 0;
}

 

一道模拟题..PAT常见排序题...注意细节就可以了...

模拟了一个小时...一次就过了 QAQ hin开心~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值