练耐心
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
List<Student2> list = new ArrayList<Student2>();
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
while (sc.hasNext()) {
Student2 s = new Student2();
s.name = sc.next();
s.score = new String[n];
for (int i = 0; i < s.score.length; i++) {
s.score[i] = sc.next();
}
list.add(s);
}
Student2[] students = new Student2[list.size()];
for (int i = 0; i < list.size(); i++) {
int count = 0;
int time = 0;
for (int j = 0; j < list.get(i).score.length; j++) {
String score = list.get(i).score[j];
char c = score.charAt(0);
if (c!='-'&&c!='0') {
count++;
}
if (c=='-'||c=='0') {
continue;
}
String a="";
String b="";
boolean boo = true;
for (int k = 0; k < score.length(); k++) {
c = score.charAt(k);
if (c>='0'&&c<='9') {
if (boo) {
a = a+c;
}else{
b = b+c;
}
}else{
boo = false;
}
}
if (!"".equals(a)) {
time += Integer.parseInt(a);
}
if (!"".equals(b)) {
time += m*Integer.parseInt(b);
}
}
students[i] = list.get(i);
students[i].count = count;
students[i].time = time;
}
Arrays.sort(students,new Comparator<Student2>() {
@Override
public int compare(Student2 o1, Student2 o2) {
if (o1.count>o2.count) {
return -1;
}
if (o1.count<o2.count) {
return 1;
}
if (o1.count==o2.count) {
if (o1.time>o2.time) {
return 1;
}
if (o1.time<o2.time) {
return -1;
}
if (o1.time == o2.time) {
if (o1.name.compareTo(o2.name)>0) {
return 1;
}
if (o1.name.compareTo(o2.name)<0) {
return -1;
}
}
}
return 0;
}
});
for (int i = 0; i < students.length; i++) {
System.out.printf("%-10s %2d %4d",students[i].name,students[i].count,students[i].time);
System.out.println();
}
sc.close();
}
}
class Student2{
String name;
String[] score;
int count;
int time;
}