本地idea debug程序真痛快
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
int n = sc.nextInt();
String s = sc.next();
int len = s.length();
int pos = 1;
int start = 1;
int end = Math.min(4,n-4+1);
for(int i = 0; i < len; i++){
char c = s.charAt(i);
if(c == 'U'){
pos--;
if(pos < 1){
pos = n;
start = Math.max(1,n-4+1);
end = n;
}else{
if(pos < start){
start = pos;
end--;
}
}
}else if(c == 'D'){
pos++;
if(pos > n){
pos = 1;
start = 1;
end = Math.min(n,4);
}else{
if(pos > end){
start++;
end++;
}
}
}
}
for(int i = start; i <= end; i++){
if(i < end) System.out.print(i + " ");
else System.out.println(i);
}
System.out.println(pos);
}
}