-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake leaderboard.java
78 lines (57 loc) · 1.78 KB
/
make leaderboard.java
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import java.util.Scanner;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Collections;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
// HashMap<String, Integer> map = new HashMap<>();
// ArrayList<String> l1 = new ArrayList<>();
// ArrayList<Integer> l2 = new ArrayList<>();
String[] l1 = new String[n];
int[] l2 = new int[n];
for(int i=0;i<n;i++)
{
l1[i]=(sc.next());
l2[i]=(sc.nextInt());
}
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(0<l1[j].compareTo(l1[j+1]))
{
String t = l1[j];
l1[j]=l1[j+1];
l1[j+1]=t;
int t1 = l2[j];
l2[j]=l2[j+1];
l2[j+1]=t1;
}
}
}
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-i-1;j++)
{
if(l2[j]<(l2[j+1]))
{
String t = l1[j];
l1[j]=l1[j+1];
l1[j+1]=t;
int t1 = l2[j];
l2[j]=l2[j+1];
l2[j+1]=t1;
}
}
}
int rank = 1;
for (int i = 0;i< n; i++)
{
if (i > 0 && l2[i] < l2[i-1])
rank=i+1;
System.out.println(rank +" "+l1[i]);
}
}
}