Water ~

Source: Internet
Author: User
Tags comparable

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 ();
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.