Advertisement
add1ctus

RobotOnMoon

Mar 1st, 2015
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. class RobotOnMoon {
  2. public:
  3.     int longestSafeCommand(vector <string> board) {
  4.        
  5.         int sx,xy,x=board.size(),y=board[0].size();
  6.        
  7.         for(int i=0;i<x;i++)
  8.             for(int j=0;j<y;j++)
  9.                 if(board[i][j]=='S')
  10.                 {
  11.                     sx=i;
  12.                     sy=j;
  13.                 }
  14.        
  15.         for(int i=0;i<x;i++)
  16.             for(int j=0;j<y;j++)
  17.                 if(board[i][j]=='#' && (i==sx || j==sy))
  18.                     return -1;
  19.        
  20.         return x+y-2;
  21.     }
  22. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement