-
Notifications
You must be signed in to change notification settings - Fork 2
/
ScannerWithSplit.java
69 lines (41 loc) · 1.22 KB
/
ScannerWithSplit.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
/*
STUDENT RATING PROGRAM
INPUT:
3
Student1 30
Student2 50
Student3 100
OUTPUT:
Student3 100
Student2 50
Student1 30
*/
import java.util.*;
import java.util.Map.Entry;
public class ScannerWithSplit{
public static void orderWithRating(){
Scanner sc = new Scanner(System.in);
TreeMap<String, Integer> tm = new TreeMap<>();
int total = sc.nextInt();
sc.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
for(int i=0; i<total; i++){
String[] key = sc.nextLine().split(" ");
int value = Integer.parseInt(key[1]);
tm.put(key[0], value);
}
sc.close();
Stack<String> st = new Stack<>();
tm.entrySet().stream()
.sorted(Map.Entry.<String, Integer>comparingByValue())
.forEach(e->{
st.push(e.getKey() + " " + e.getValue());
});
Iterator<String> it = st.iterator();
while(it.hasNext()){
System.out.println(st.pop());
}
}
public static void main(String[] args){
orderWithRating();
}
}