-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnakeCoup.java
45 lines (41 loc) · 1.4 KB
/
snakeCoup.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
import java.util.Scanner;
/**
* Created by Kavish Kapadia on 31-05-2017.
*/
public class snakeCoup {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int test = in.nextInt();
for (int i = 0; i < test; i++) {
int n = in.nextInt();
// char arr[][] = new char[2][n];
String data[] = new String[2];
for(int j = 0; j < 2; j++)
data[j] = in.next();
System.out.println(snakeCoupMongoose(data, n));
}
}
private static int snakeCoupMongoose(String[] data, int n) {
boolean horizon = data[0].indexOf('*') >= 0 && data[1].indexOf('*') >= 0;
int c = 0;
boolean up = false, down = false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
if (data[j].charAt(i) == '*') {
if((j == 0 && up) || (j==1 && down)){
c++;
up = down = false;
break;
}
}
}
for (int j = 0; j < 2; j++) {
if (data[j].charAt(i) == '*' && j == 0)
up = true;
if (data[j].charAt(i) == '*' && j == 1)
down = true;
}
}
return c + (horizon ? 1 : 0);
}
}