fork download
  1. public class RobotOnMoonEasy
  2. {
  3. public String isSafeCommand(String[] board, String S)
  4. {
  5. int n = board.length;
  6. int m = board[0].length();
  7. int x = 0, y = 0;
  8. for(int i = 0; i < n; i++)
  9. for(int j = 0; j < m; j++)
  10. if(board[i].charAt(j) == 'S')
  11. {
  12. x = i;
  13. y = j;
  14. }
  15. for(int i = 0; i < S.length(); i++)
  16. {
  17. int nx = x, ny = y;
  18. if(S.charAt(i) == 'U') nx --;
  19. if(S.charAt(i) == 'D') nx ++;
  20. if(S.charAt(i) == 'L') ny --;
  21. if(S.charAt(i) == 'R') ny ++;
  22. if(nx < 0 || nx >= n || ny < 0 || ny >= m)
  23. return "Dead";
  24. if(board[nx].charAt(ny) == '#')
  25. continue;
  26. x = nx;
  27. y = ny;
  28. }
  29. return "Alive";
  30. }
  31. }
  32.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class RobotOnMoonEasy is public, should be declared in a file named RobotOnMoonEasy.java
public class RobotOnMoonEasy
       ^
1 error
stdout
Standard output is empty