2017年9月1日 星期五

UVA118:Mutant Flatworld Explorers

  1. import java.util.*;  
  2. class main{  
  3. public static char Turn(char bot,char con){  
  4. if(con=='R'){  
  5. switch(bot){  
  6. case 'E':  
  7.   return 'S';  
  8. case 'S':  
  9.   return 'W';  
  10. case 'W':  
  11.   return 'N';  
  12. case 'N':  
  13.   return 'E';        
  14. }  
  15. }else if(con=='L'){  
  16. switch(bot){  
  17. case 'E':  
  18.   return 'N';  
  19. case 'S':  
  20.   return 'E';  
  21. case 'W':  
  22.   return 'S';  
  23. case 'N':  
  24.   return 'W';        
  25. }  
  26. }  
  27.  return '0';  
  28. }  
  29. public static void main(String[] args){  
  30. Scanner sc = new Scanner(System.in);  
  31. int X=sc.nextInt(),Y=sc.nextInt();  
  32. int[][] map=new int[50][50];  
  33. while(sc.hasNext()){  
  34. int x=sc.nextInt(),y=sc.nextInt(); char robot =sc.next().charAt(0);   
  35. sc.nextLine();//pass  
  36. String cmd=sc.nextLine(),Lost="";  
  37.   for(int i=0;i<cmd.length();i++){  
  38.     if(cmd.charAt(i)=='R') robot=Turn(robot,'R');  
  39.     else if(cmd.charAt(i)=='L') robot=Turn(robot,'L');  
  40.     else if(cmd.charAt(i)=='F'){  
  41.       if(robot=='E'&&x<X) x++;  
  42.       else if(robot=='W'&&x>0) x--;  
  43.       else if(robot=='N'&&y<Y) y++;  
  44.       else if(robot=='S'&&y>0) y--;  
  45.       else{  
  46.         if(map[y][x]==1continue;  
  47.          map[y][x]=1; Lost=" LOST"break;  
  48.       }  
  49.     }  
  50.   }  
  51.   System.out.println(x+" "+y+" "+robot+Lost); Lost="";  
  52. }  
  53. }  
  54.   
  55.   
  56.   
  57. }  

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。