To change this license header choose License Headers in Project Proper

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.*;
/**
*
* @author alpha-pc
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
String line = sc.nextLine();
String[] sp;
String[] name = new String[n];
int[] rez = new int[n];
for (int i = 0; i < n; i++) {
line = sc.nextLine();
sp = line.split(" ");
name[i] = sp[0] + " " + sp[1];
for (int j = 2; j < 2 + m; j++) {
rez[i] += Integer.valueOf(sp[j]);
}
}
for (int j = 0; j < name.length - 1; j++) {
for (int i = 0; i < name.length - j - 1; i++) {
if (rez[i] < rez[i + 1]) {
int tempRez = rez[i];
rez[i] = rez[i + 1];
rez[i + 1] = tempRez;
String tempName = name[i];
name[i] = name[i + 1];
name[i + 1] = tempName;
}
}
}
int position = 1;
System.out.println(name[0] + " " + rez[0] + " " + position);
for (int i = 1; i < n; i++) {
if(rez[i] != rez[i - 1]) {
position++;
}
System.out.println(name[i] + " " + rez[i] + " " + position);
}
}
}