-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCookingWater.java
More file actions
37 lines (31 loc) · 1.12 KB
/
Copy pathCookingWater.java
File metadata and controls
37 lines (31 loc) · 1.12 KB
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
import java.util.HashMap;
import java.util.Scanner;
public class CookingWater {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int n = sc.nextInt();
sc.nextLine();
HashMap<Integer, Integer> map = createMap(n);
if(isSameTime(n, map)) System.out.println("gunilla has a point");
else System.out.println("edward is right");
}
public static boolean isSameTime(int n, HashMap<Integer, Integer> map) {
// loop throug map and find if there is a time where count (value) is same as n
for (Integer count : map.values()) {
if(count == n) return true;
}
return false;
}
public static HashMap<Integer, Integer> createMap(int n) {
HashMap<Integer, Integer> map = new HashMap<>();
int low, high;
for (int i = 0; i < n; i++) {
low = sc.nextInt(); high = sc.nextInt();
for (int j = low; j <= high; j++) {
if(map.containsKey(j)) map.put(j,map.get(j)+1);
else map.put(j, 1);
}
}
return map;
}
}