Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
高手帮帮忙,我调得要死了,不知道错哪了import java.io.*; import java.util.*; class Player implements Comparable<Player> { int num; String name; char role; int year; public Player(char role,String name,int num,int year) { this.role=role;this.name=name;this.num=0;this.year=0; } public int compareTo(Player other) { if(num<other.num) return -1; else if(num>other.num) return 1; else return 0; } } public class Main { public static void main(String[] args) { Scanner cin=new Scanner(System.in); TreeSet<Player> setG=new TreeSet<Player>(); TreeSet<Player> setD=new TreeSet<Player>(); TreeSet<Player> setM=new TreeSet<Player>(); TreeSet<Player> setS=new TreeSet<Player>(); String s; StringTokenizer st; int a,b; int needD,needM,needS; Player p; Player[] all; while(!(s=cin.nextLine()).equals("0")) { needD=0;needM=0;needS=0; st=new StringTokenizer(s,"- "); p=new Player(' ',"",0,0); p.num=Integer.valueOf(st.nextToken()); p.name=st.nextToken(); p.role=st.nextToken().charAt(0); while(st.hasMoreTokens()) { a=Integer.valueOf(st.nextToken()); b=Integer.valueOf(st.nextToken()); p.year=p.year+b-a+1; } switch(p.role) { case 'G': setG.add(p); break; case 'D': setD.add(p); break; case 'M': setM.add(p); break; case 'S': setS.add(p); break; } for(int i=0;i<21;i++) { s=cin.nextLine(); st=new StringTokenizer(s,"- "); p=new Player(' ',"",0,0); p.num=Integer.valueOf(st.nextToken()); p.name=st.nextToken(); p.role=st.nextToken().charAt(0); while(st.hasMoreTokens()) { a=Integer.valueOf(st.nextToken()); b=Integer.valueOf(st.nextToken()); p.year=p.year+b-a+1; } switch(p.role) { case 'G': setG.add(p); break; case 'D': setD.add(p); break; case 'M': setM.add(p); break; case 'S': setS.add(p); break; } }///读到第二十二行 s=cin.nextLine(); st=new StringTokenizer(s,"- "); needD=Integer.valueOf(st.nextToken()); needM=Integer.valueOf(st.nextToken()); needS=Integer.valueOf(st.nextToken()); if(setG.size()<1||(setD.size()<needD)||(setM.size()<needM)||setS.size()<needS) { System.out.println("IMPOSSIBLE TO ARRANGE"); System.out.println(); continue; } all=new Player[11]; all[0]=setG.first(); for(int i=1;i<=needD;i++) { all[i]=setD.first(); setD.remove(setD.first()); } for(int i=needD+1;i<=needD+needM;i++) { all[i]=setM.first(); setM.remove(setM.first()); } for(int i=needD+needM+1;i<=10;i++) { all[i]=setS.first(); setS.remove(setS.first()); } int big=0; for(int i=1;i<11;i++) { if(all[i].year>all[big].year) big=i; else if(all[i].year==all[big].year&&all[i].num>all[big].num) big=i; } System.out.println(all[big].num+" "+all[big].name+" "+all[big].role); for(int i=0;i<11;i++) { if(i==big) continue; else System.out.println(all[i].num+" "+all[i].name+" "+all[i].role); } System.out.println(); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator