原题链接在这:
我的代码:
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
for (int i = 1; i <= t; i++) {
int N=in.nextInt();
int R=in.nextInt();
int C=in.nextInt();
int SR=in.nextInt();
int SC=in.nextInt();
String ins=in.next();
char[] ins_array=new char[N];
for(int j=0;j<N;j++) {
ins_array[j]=ins.charAt(j);
}
boolean[][] arrived=new boolean[R+1][C+1];
arrived[SR][SC]=true;
for(int j=0;j<N;j++) {
if(ins_array[j]=='N') {//R--
while(arrived[SR-1][SC]==true) {
SR--;
}
if(R>1) {
SR--;
arrived[SR][SC]=true;
}
}
else if(ins_array[j]=='S') {//R++
while(arrived[SR+1][SC]==true) {
SR++;
}
if(SR<R) {
SR++;
arrived[SR][SC]=true;
}
}else if(ins_array[j]=='E') {//C++
while(arrived[SR][SC+1]==true) {
SC++;
arrived[SR][SC]=true;
}
if(SC<C) {
SC++;
arrived[SR][SC]=true;
}
}else if(ins_array[j]=='W') {//C--
while(arrived[SR][SC-1]==true) {
SC--;
arrived[SR][SC]=true;
}
if(SC>1) {
SC--;
arrived[SR][SC]=true;
}
}
}
System.out.println("Case #" + i + ": "+SR+" "+SC);
}
in.close();
}
}
可以过测试样例,但是上测试数据集会出现RE(运行错误),暂且还没有找到错误原因。