-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnakeProcession.java
More file actions
35 lines (33 loc) · 1.03 KB
/
snakeProcession.java
File metadata and controls
35 lines (33 loc) · 1.03 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
import java.util.Scanner;
/**
* Created by Kavish Kapadia on 20-05-2017.
*/
class snakeProcession {
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();
String data = in.next();
String ans = validSnakeProcession(n, data);
System.out.println(ans);
}
}
private static String validSnakeProcession(Integer n, String data) {
Boolean result = true;
for(int i = 0; i < n; i++){
if((result && data.charAt(i) == 'T') || (!result && data.charAt(i) == 'H')) {
result = false;
break;
}
else if(data.charAt(i) == 'H')
result = false;
else if(!result && data.charAt(i) == 'T')
result = true;
}
if(result)
return "Valid";
else
return "Invalid";
}
}