I haven't written a question for a long time. I found a question in the water category in the hdoj category. By the way, I will briefly review the Java sorting.
Paste downCode:
HDU 1084
Import Java. util. * ;
Class Rank Implements Comparable < Rank > {
/* When designing a class, implement the comparable interface and rewrite its compareto method,
* To sort data in the specified order. */
Int Idx;
Int CNT;
String Ti;
Int Score;
Public Rank ( Int Idx, Int CNT, string Ti ){
This . Idx = Idx;
This . CNT = CNT;
This . Ti = Ti;
This . Score = 50 + CNT * 10 ;
}
Public Int Compareto (Rank B ){
/* For example, return this. CNT-B. CNT; is sorted by CNT in ascending order. */
Rank = This ;
If (A. CNT < B. CNT ){
Return 1 ;
} Else If (A. CNT = B. CNT ){
If (A. Ti. compareto (B. Ti) < 0 ){
Return - 1 ;
}
Return 1 ;
} Else {
Return - 1 ;
}
}
}
Public Class Main {
Public Static Void Main (string [] ARGs ){
Scanner CIN = New Using (system. In );
Rank [] rank = New Rank [ 110 ];
Rank [] ans = New Rank [ 110 ];
Int NN [] = New Int [ 110 ];
While (CIN. hasnextint ()){
Int N = Cin. nextint ();
If (N < 0 ) Break ;
Arrays. Fill (NN, 0 );
For ( Int I = 0 ; I < N; I ++ ){
Int A = Cin. nextint ();
String Ti = Cin. Next ();
Rank [I] = New Rank (I, A, Ti );
NN [A] ++ ;
}
Arrays. Sort (rank, 0 , N );
For ( Int I = 0 ; I < N; I ++ ){
If (Rank [I]. CNT < 5 && Rank [I]. CNT > 0 ){
Int TT = I + NN [rank [I]. CNT] / 2 ;
For ( Int J = I; j < TT; j ++ ){
Rank [J]. Score + = 5 ;
}
I + = NN [rank [I]. CNT] - 1 ;
}
}
For ( Int I = 0 ; I < N; I ++ )
Ans [rank [I]. idx] = Rank [I];
For ( Int I = 0 ; I < N; I ++ )
System. Out. println (ANS [I]. Score );
System. Out. println ();
}
}
}