Input輸入數據的第一行是考試題數n(1≤n≤12)以及單位罰分數m(10≤m≤20),每行數據描述一個學生的用戶名(很少於10個字符的字串)以及對全部n道題的答題現狀,其描述採用問題描述中的數量標記的格式,見上面的表格,提交次數老是小於100,AC所耗時間老是小於1000。
Output將這些學生的考試現狀,輸出一個實時排名。實時排名顯然先按AC題數的多少排,多的在前,再按時間分的多少排,少的在前,若是湊巧前二者都相等,則按名字的字典序排,小的在前。每一個學生佔一行,輸出名字(10個字符寬),作出的題數(2個字符寬,右對齊)和時間分(4個字符寬,右對齊)。名字、題數和時間分相互之間有一個空格。
Sample Inputjava
8 20 Smith -1 -16 8 0 0 120 39 0 John 116 -2 11 0 0 82 55(1) 0 Josephus 72(3) 126 10 -3 0 47 21(2) -2 Bush 0 -1 -8 0 0 0 0 0 Alice -2 67(2) 13 -1 0 133 79(1) -1 Bob 0 0 57(5) 0 0 168 -7 0
Sample Outputnode
Josephus 5 376 John 4 284 Alice 4 352 Smith 3 167 Bob 2 325 Bush 0 0
注意:題目沒有給出說明輸入的數量,因此輸入是直到文件的末尾
代碼:
import java.util.Scanner; import java.util.Arrays; import java.util.Scanner; class node implements Comparable<node>{ int ac; int time; String name; @Override public int compareTo(node o) { if(this.ac!=o.ac) return o.ac-this.ac;//從大到小 else { if(this.time!=o.time) return this.time-o.time; else return this.name.compareTo(o.name);//從小到大 } } } public class Main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int m=scan.nextInt(); node a[]=new node[10005]; int i=0; while(scan.hasNext()){ a[i]=new node(); a[i].name=scan.next(); for(int j=0;j<n;j++){ String s=scan.next(); if(s.charAt(0)=='0') continue; else if(s.charAt(0)=='-') continue; else if(s.charAt(0)>'0'&&s.charAt(0)<='9'){ a[i].ac++; if(s.indexOf('(')<0){ a[i].time+=Integer.parseInt(s); } else{ String ls=s.substring(0,s.indexOf('(')); a[i].time+=Integer.parseInt(ls); String rs=s.substring(s.indexOf('(')+1,s.indexOf(')')); a[i].time+=m*Integer.parseInt(rs); } } } i++; } Arrays.sort(a,0,i); for(int j=0;j<i;j++){//wrong在i System.out.printf("%-10s%3d%5d",a[j].name,a[j].ac,a[j].time); System.out.println(); } } }