-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkickStartPainter.java
47 lines (43 loc) · 1.7 KB
/
kickStartPainter.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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int cases = in.nextInt();
for (int t = 1; t <= cases; t++) {
int length = in.nextInt();
String p = in.next();
HashMap<Character, String> composedColors = new HashMap<>();
HashMap<Character, Integer> colorIndex = new HashMap<>();
int strokCount = 0;
composedColors.put('O',"RY");
composedColors.put('P',"RB");
composedColors.put('G',"YB");
composedColors.put('A',"RYB");
for (int i=0; i<p.length() ; i++ ) {
if (!composedColors.containsKey(p.charAt(i))) {
if(colorIndex.containsKey(p.charAt(i))
&& i - colorIndex.get(p.charAt(i)) ==1){
//Nothing
}else{
strokCount = strokCount +1;
}
colorIndex.put(p.charAt(i), i);
} else{
String str = composedColors.get(p.charAt(i));
for (int j =0 ;j< str.length() ; j++ ) {
if(colorIndex.containsKey(str.charAt(j))
&& i - colorIndex.get(str.charAt(j)) ==1){
//Nothing
}else{
strokCount = strokCount +1;
}
colorIndex.put(str.charAt(j), i);
}
}
}
System.out.printf("Case #%d: %d\n", t, strokCount);
}
in.close();
}
}