-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC1.java
More file actions
31 lines (30 loc) · 1.01 KB
/
Copy pathC1.java
File metadata and controls
31 lines (30 loc) · 1.01 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
import java.util.Scanner;
public class C1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
for (int i = 0; i < t; i++) {
int n = scanner.nextInt();
int a = scanner.nextInt();
int b = scanner.nextInt();
String moves = scanner.next();
int x=0,y=0;
String str="NO";
x: while(x<=a && y<=b) {
for (int j = 0; j < n; j++) {
if (moves.charAt(j) == 'N') y++;
else if (moves.charAt(j) == 'E') x++;
else if (moves.charAt(j) == 'S') y--;
else if (moves.charAt(j) == 'W') x--;
if(x==a && y==b){
str="YES";
break x;
} else if (x==0 && y==0) {
break x;
}
}
}
System.out.println(str);
}
}
}