comparable 奖牌榜 金银铜牌

来源:互联网 发布:多种乐器软件 编辑:程序博客网 时间:2024/05/15 19:31
import java.util.Arrays;
public class Result implements Comparable{
 int j;
 int y;
 int t;
 public Result(int j,int y,int t)
 {
  this.j = j;
  this.y = y;
  this.t = t;
 }
 public int compareTo(Object o) {
  int point_j = ((Result)o).j;
  int point_y = ((Result)o).y;
  int point_t = ((Result)o).t;
  int returnValue=0;
 // if(j<point_j)
 //  returnValue=-1;
 // else{
 //  if(j>point_j)
 //   returnValue=1;
 //  else{
 //   if(y<point_y)
 //    returnValue=-1;
 //   else{
 //    if(y>point_y)
 //     returnValue=1;
 //    else{
 //     if(t<point_t)
 //      returnValue=-1;
 //     else{
 //      if(t==point_t)
 //       returnValue=0;
 //      else returnValue=1;
 //       
 //     }
 //    }
 ///    
 //   }
 //  }
 // }
  return j<point_j? 1:(j>point_j?-1:(y<point_y?1:(y>point_y?-1:(t<point_t?1:(t>point_t?-1:0)))));
 } 
 public static void main(String[] args) {
  Result[] ra = {new Result(50,2,30),new Result(50,2,56),new Result(86,3,43)};
  Arrays.sort(ra);
  for(int i=0;i<ra.length;i++)
  {
   System.out.println(ra[i].j + "," +ra[i].y+","+ra[i].t);
  }
 }
}