-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackingcups.java
More file actions
39 lines (36 loc) · 976 Bytes
/
stackingcups.java
File metadata and controls
39 lines (36 loc) · 976 Bytes
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
import java.util.*;
import java.io.*;
public class stackingcups{
public static void main(String[] args) throws Exception{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.parseInt(bf.readLine());
String s = "";
TreeMap<Integer,String> tm = new TreeMap<Integer,String>();
while((s = bf.readLine()) != null) {
String [] sar = s.split(" ");
int radius = 0;
int diameter = 0;
if(IsNumber(sar[1]) == true) {
radius = Integer.parseInt(sar[1]);
tm.put(radius,sar[0]);
}
else {
diameter = Integer.parseInt(sar[0]);
radius = diameter/2;
tm.put(radius,sar[1]);
}
}
for(Map.Entry m:tm.entrySet()) {
System.out.println(m.getValue());
}
}
public static boolean IsNumber(String s) {
try {
int i = Integer.parseInt(s);
return true;
}
catch (NumberFormatException er){
return false;
}
}
}