ACM罚时
package day_1_17 ;
import java. util. ArrayList ;
import java. util. HashMap ;
import java. util. List ;
import java. util. Map ;
import java. util. Scanner ;
public class C {
public static class Record {
public int hour;
public int minute;
public String problem;
public String state;
public Record ( int h, int m, String p, String s) {
hour= h;
minute= m;
problem= p;
state= s;
}
}
public static void main ( String [ ] args) {
Scanner scan= new Scanner ( System . in) ;
int n;
while ( scan. hasNext ( ) ) {
n= scan. nextInt ( ) ;
List < Record > list= new ArrayList < > ( ) ;
scan. nextLine ( ) ;
for ( int i= 0 ; i< n; ++ i) {
String str= scan. nextLine ( ) ;
String [ ] strs= str. split ( " " ) ;
char [ ] chs= strs[ 0 ] . toCharArray ( ) ;
int h= ( chs[ 0 ] - '0' ) * 10 + ( chs[ 1 ] - '0' ) ;
int m= ( chs[ 3 ] - '0' ) * 10 + ( chs[ 4 ] - '0' ) ;
String p= strs[ 1 ] ;
String s= strs[ 2 ] ;
list. add ( new Record ( h, m, p, s) ) ;
}
int H = 0 , M = 0 ;
Map < String , Integer > map= new HashMap < > ( ) ;
for ( int i= 0 ; i< n; ++ i) {
if ( list. get ( i) . state. equals ( "AC" ) ) {
if ( ! map. containsKey ( list. get ( i) . problem) ) {
map. put ( list. get ( i) . problem, i) ;
H += list. get ( i) . hour- 18 ;
M += list. get ( i) . minute;
}
}
}
for ( String key: map. keySet ( ) ) {
for ( int j= 0 ; j< map. get ( key) ; ++ j) {
if ( list. get ( j) . problem. equals ( key) ) {
M += 20 ;
}
}
}
H += ( M / 60 ) ;
M = M % 60 ;
String res= "" ;
if ( H < 10 ) {
res+= "0" + H ;
}
else res+= H ;
res+= ":" ;
if ( M < 10 ) res+= "0" + M ;
else res+= M ;
System . out. println ( res) ;
}
}
}