-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRingsAndRods.java
More file actions
74 lines (55 loc) · 1.35 KB
/
Copy pathRingsAndRods.java
File metadata and controls
74 lines (55 loc) · 1.35 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package abc;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class RingsAndRods {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
RingsAndRods rr = new RingsAndRods();
System.out.println("Enter String: ");
String str = sc.next();
int res = rr.countPoints(str);
System.out.println(res);
}
public int countPoints(String rings) {
String []str = rings.split("");
Map m = new HashMap();
List green = new LinkedList();
List red = new LinkedList();
List blue = new LinkedList();
int count = 0;
for(int i=0; i<str.length; i++) {
if(str[i].equals("R")) {
red.add(str[i+1]);
i++;
}
else if(str[i].equals("G")){
green.add(str[i+1]);
i++;
}
else{
blue.add(str[i+1]);
i++;
}
}
for(int i=0; i<green.size(); i++) {
String x = (String) green.get(i);
for(int j=0; j<red.size(); j++) {
String y = (String) red.get(j);
if(x.equals(y)) {
for(int k=0; k<blue.size(); k++) {
String z = (String) blue.get(k);
if(x.equals(z) && y.equals(z)) {
count++;
break;
}
}
}
break;
}
}
return count;
}
}