package newpackage;
import java.util.*;
public class challange {
public static void main(String[]args) {
Scanner sc=new Scanner(System.in);
int xboard=sc.nextInt(),yboard=sc.nextInt();
sc.nextLine();
Map<String,ArrayList<Character>>memo=new HashMap<>();
while(sc.hasNextLine()) {
boolean head=false;
String []code1=sc.nextLine().split(" ");
char []code2=sc.nextLine().toCharArray();
rob therob=new rob(Integer.parseInt(code1[0]),Integer.parseInt(code1[1]),(char) code1[2].toCharArray()[0]);
for(char c:code2) {
if(c=='R') {
switch(therob.way) {
case('N'):
therob.way='E';
break;
case('S'):
therob.way='W';
break;
case('E'):
therob.way='S';
break;
case('W'):
therob.way='N';
break;
}
}
if(c=='L') {
switch(therob.way) {
case('N'):
therob.way='W';
break;
case('S'):
therob.way='E';
break;
case('E'):
therob.way='N';
break;
case('W'):
therob.way='S';
break;
}
}
if(c=='F') {
String sp=therob.x+","+therob.y;
switch(therob.way) {
case('N'):
if(memo.get(sp)==null||!memo.get(sp).contains('N'))
therob.y++;
break;
case('S'):
if(memo.get(sp)==null||!memo.get(sp).contains('S'))
therob.y--;
break;
case('W'):
if(memo.get(sp)==null||!memo.get(sp).contains('W'))
therob.x--;
break;
case('E'):
if(memo.get(sp)==null||!memo.get(sp).contains('E'))
therob.x++;
break;
}
if(therob.x<0||therob.x>xboard||therob.y<0||therob.y>yboard) {
if(memo.get(sp)==null)
memo.put(sp,new ArrayList<>());
memo.get(sp).add(therob.way);
switch(therob.way) {
case('N'):
therob.y--;
break;
case('S'):
therob.y++;
break;
case('E'):
therob.x--;
break;
case('W'):
therob.x++;
break;
}
System.out.println(therob.x+" "+therob.y+" "+therob.way+" LOST");
head=true;
break;
}
}
}
if(!head)
System.out.println(therob.x+" "+therob.y+" "+therob.way);
}
}
}
class rob {
char way;
int x,y;
public rob(int x,int y,char way) {
this.x=x;
this.y=y;
this.way=way;
}
}
package newpackage;
import java.util.*;
public class challange {
public static void main(String[]args) {
Scanner sc=new Scanner(System.in);
int xboard=sc.nextInt(),yboard=sc.nextInt();
sc.nextLine();
Map>memo=new HashMap<>();
while(sc.hasNextLine()) {
boolean head=false;
String []code1=sc.nextLine().split(" ");
char []code2=sc.nextLine().toCharArray();
rob therob=new rob(Integer.parseInt(code1[0]),Integer.parseInt(code1[1]),(char) code1[2].toCharArray()[0]);
for(char c:code2) {
if(c=='R') {
switch(therob.way) {
case('N'):
therob.way='E';
break;
case('S'):
therob.way='W';
break;
case('E'):
therob.way='S';
break;
case('W'):
therob.way='N';
break;
}
}
if(c=='L') {
switch(therob.way) {
case('N'):
therob.way='W';
break;
case('S'):
therob.way='E';
break;
case('E'):
therob.way='N';
break;
case('W'):
therob.way='S';
break;
}
}
if(c=='F') {
String sp=therob.x+","+therob.y;
switch(therob.way) {
case('N'):
if(memo.get(sp)==null||!memo.get(sp).contains('N'))
therob.y++;
break;
case('S'):
if(memo.get(sp)==null||!memo.get(sp).contains('S'))
therob.y--;
break;
case('W'):
if(memo.get(sp)==null||!memo.get(sp).contains('W'))
therob.x--;
break;
case('E'):
if(memo.get(sp)==null||!memo.get(sp).contains('E'))
therob.x++;
break;
}
if(therob.x<0||therob.x>xboard||therob.y<0||therob.y>yboard) {
if(memo.get(sp)==null)
memo.put(sp,new ArrayList<>());
memo.get(sp).add(therob.way);
switch(therob.way) {
case('N'):
therob.y--;
break;
case('S'):
therob.y++;
break;
case('E'):
therob.x--;
break;
case('W'):
therob.x++;
break;
}
System.out.println(therob.x+" "+therob.y+" "+therob.way+" LOST");
head=true;
break;
}
}
}
if(!head)
System.out.println(therob.x+" "+therob.y+" "+therob.way);
}
}
}
class rob {
char way;
int x,y;
public rob(int x,int y,char way) {
this.x=x;
this.y=y;
this.way=way;
}
}
阿...我搞錯了,角落是不會錯兩次才對