- import java.util.*;
- class main{
- public static char Turn(char bot,char con){
- if(con=='R'){
- switch(bot){
- case 'E':
- return 'S';
- case 'S':
- return 'W';
- case 'W':
- return 'N';
- case 'N':
- return 'E';
- }
- }else if(con=='L'){
- switch(bot){
- case 'E':
- return 'N';
- case 'S':
- return 'E';
- case 'W':
- return 'S';
- case 'N':
- return 'W';
- }
- }
- return '0';
- }
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- int X=sc.nextInt(),Y=sc.nextInt();
- int[][] map=new int[50][50];
- while(sc.hasNext()){
- int x=sc.nextInt(),y=sc.nextInt(); char robot =sc.next().charAt(0);
- sc.nextLine();//pass
- String cmd=sc.nextLine(),Lost="";
- for(int i=0;i<cmd.length();i++){
- if(cmd.charAt(i)=='R') robot=Turn(robot,'R');
- else if(cmd.charAt(i)=='L') robot=Turn(robot,'L');
- else if(cmd.charAt(i)=='F'){
- if(robot=='E'&&x<X) x++;
- else if(robot=='W'&&x>0) x--;
- else if(robot=='N'&&y<Y) y++;
- else if(robot=='S'&&y>0) y--;
- else{
- if(map[y][x]==1) continue;
- map[y][x]=1; Lost=" LOST"; break;
- }
- }
- }
- System.out.println(x+" "+y+" "+robot+Lost); Lost="";
- }
- }
- }
2017年9月1日 星期五
UVA118:Mutant Flatworld Explorers
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。