PAT A1075 PAT Judge
int scores[6] = {-2};是个低级错误,这样只初始化了第一个元素,其他为0 goodboy的判断条件应该是if(score >= 0),不能丢掉=0,否则0分的同学不能输出,好像是第三个测试点吧 虽然小于0用了-2和-1两个状态,其实一个就够了。在有效输出的情况下,编译不过的输出0,没有提交的题目输出-。所以把编译不过的-1合并到0分上面 最后一个测试点貌似是有ID小但是没有成功提交记录的人(得分为初始的0分),和ID大成功提交但得0分的人,之前是把第一个人单独先输出的,没考虑到他可能是无效的。还是乖乖排个序,把有效的放前面方便点
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
using namespace std;
struct Student{
int ID;
int scores[ 6 ] = { - 2 } ;
int perfect_num = 0 ;
int total = 0 ;
bool goodboy = true ;
Student ( ) {
fill ( scores, scores + 6 , - 2 ) ;
}
} ;
vector< Student> vs;
vector< int > ps;
bool cmp ( Student s1, Student s2) {
if ( s1. goodboy != s2. goodboy) return s1. goodboy < s2. goodboy;
else if ( s1. total != s2. total) return s1. total > s2. total;
else if ( s1. perfect_num != s2. perfect_num) return s1. perfect_num > s2. perfect_num;
else return s1. ID < s2. ID;
}
#define DEBUG 1
int main ( ) {
#ifdef DEBUG
freopen ( "1.txt" , "r" , stdin ) ;
#endif
int stnum, prnum, sunum;
cin >> stnum >> prnum >> sunum;
vs. resize ( stnum + 1 ) ;
ps. resize ( prnum + 1 ) ;
for ( int i = 1 ; i <= prnum; i ++ ) cin >> ps[ i] ;
for ( int i = 0 ; i < sunum; i ++ ) {
int id, pid, score;
cin >> id >> pid >> score;
vs[ id] . ID = id;
if ( vs[ id] . scores[ pid] < score) {
if ( vs[ id] . scores[ pid] > 0 ) vs[ id] . total - = vs[ id] . scores[ pid] ;
if ( score > 0 ) vs[ id] . total + = score;
vs[ id] . scores[ pid] = score;
if ( score == ps[ pid] ) vs[ id] . perfect_num ++ ;
if ( score >= 0 ) vs[ id] . goodboy = false ;
}
}
sort ( vs. begin ( ) + 1 , vs. end ( ) , cmp) ;
int rank = 1 ;
for ( int i = 1 ; i < vs. size ( ) && ! vs[ i] . goodboy; i ++ ) {
if ( i > 1 && vs[ i] . total < vs[ i - 1 ] . total) rank = i;
printf ( "%d %05d %d" , rank, vs[ i] . ID, vs[ i] . total) ;
for ( int j = 1 ; j <= prnum; j ++ ) {
if ( vs[ i] . scores[ j] == - 2 ) printf ( " -" ) ;
else if ( vs[ i] . scores[ j] == - 1 ) printf ( " 0" ) ;
else printf ( " %d" , vs[ i] . scores[ j] ) ;
}
printf ( "\n" ) ;
}
return 0 ;
}