-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnterTheMatrix.java
More file actions
69 lines (66 loc) · 1.33 KB
/
EnterTheMatrix.java
File metadata and controls
69 lines (66 loc) · 1.33 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
package codechef;
import java.io.*;
public class EnterTheMatrix {
/**
* @param args
*/
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
short t = Short.parseShort(br.readLine());
while(t>0){
String cy = br.readLine();
int min = Integer.MAX_VALUE;
int currentmin = 0;
int count = 0;
char cypher[] = cy.toCharArray();
for(int k = 0 ; k<cypher.length-2 ; k++){
count=0;
currentmin = 0;
int c1 = 0,c2 = 0,c3 =0;
char p = ' ';
for(int i = k ; count!=3 && i<cypher.length ; i++){
switch(cypher[i]){
case 'R' :{
currentmin++;
if(count==1 && p == 'R'){
k = i-1;
}
c1 =1;
p = 'R';
break;
}
case 'G' :{
currentmin++;
if(count==1 && p == 'G'){
k = i-1;
}
c2 = 1;
p = 'G';
break;
}
case 'B' :{
currentmin++;
if(count==1 && p == 'B'){
k = i-1;
}
c3 = 1;
p = 'B';
break;
}
default : {};
}
count = c1 + c2 +c3;
if(count == 3){
if(min>currentmin){
min = currentmin;
}
c1 = c2 = c3 = 0;
}
}
}
System.out.println(min);
t--;
}
}
}