-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ1.java
More file actions
59 lines (49 loc) · 1.96 KB
/
Copy pathQ1.java
File metadata and controls
59 lines (49 loc) · 1.96 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package Assignment;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class Q1 {
public static void main(String[] args) throws IOException {
// String door_fitting[] = {"Room Number 1", "Secret room"};
// String codes[] = {"910", "811"};
String door_fitting[] = {"Room 666", "Don't enter"};
String codes[] = {"313", "800"};
// String door_fitting[] = {"Portal 1", "Portal 2", "Portal 3"};
// String codes[] = {"501"};
// String door_fitting[] = {"Door to nowhere", "Door to nowhere 2"};
// String codes[] = {"1203", "1203"};
int n = door_fitting.length;
Map<String, Integer> mp = new HashMap<>();
for (int i = 0; i < n; i++) {
mp.put(codes[i], mp.getOrDefault(codes[i], 0) + 1);
}
StringBuilder ans = new StringBuilder();
for (int i = 0; i < n; i++) {
int m = door_fitting[i].length();
int l = 0;
int d = 0;
boolean r = false;
for (int j = 0; j < m; j++) {
if (Character.isLowerCase(door_fitting[i].charAt(j))) {
l++;
}
if (Character.isDigit(door_fitting[i].charAt(j))) {
d++;
}
}
for (int j = 0; j < n - 4; j++) {
String data = door_fitting[i].substring(j, j + 4).toLowerCase();
if (data.equals("room")) {
r = true;
break;
}
}
String x = l + (r ? "1" : "0") + d;
if (mp.getOrDefault(x, 0) == 0) {
continue;
}
ans.append(door_fitting[i]).append("-").append(l).append((r ? "1" : "0")).append(d).append(";");
}
System.out.println(ans);
}
}