PAT_1075. PAT Judge
来源:互联网 发布:js如何隐藏div 编辑:程序博客网 时间:2024/06/02 03:41
//// 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
- PAT_1075. PAT Judge
- PAT 1075. PAT Judge
- PAT-1075. PAT Judge
- pat 1075 PAT Judge
- 【PAT】1075. PAT Judge
- PAT--1075. PAT Judge
- PAT 1075. PAT Judge (25)
- PAT 1075. PAT Judge (25)
- [DS][Sort][PAT][PAT Judge]
- 【PAT】1075. PAT Judge (25)
- PAT A1075. PAT Judge (25)
- 1075. PAT Judge
- 1075. PAT Judge
- 1075. PAT Judge (25)
- 1075. PAT Judge (25)
- 1075.PAT Judge
- 1075. PAT Judge (25)
- pat1075 PAT Judge
- Python3.5连接Mysql
- 函数返回数组指针的几种声明方式
- RestFul Api 定义流程规范
- c++记录
- “TypeError: 'dict_keys' object is not subscriptable”
- PAT_1075. PAT Judge
- Android开发之选取手机图片
- 针对二分类问题的对数几率模型
- linux环境下编译链接汇编语言
- win10交换Caps和Ctrl
- SQL Server 2005 (64)免费下载并配置网络
- 学习笔记TF044:TF.Contrib组件、统计分布、Layer、性能分析器tfprof
- 阿里2017年校招
- 设计模式之组合模式