1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| #include<bits/stdc++.h> using namespace std;
int arr[55][55];
int checkbound(int tmpx, int tmpy, int rectlength, int rectwidth){ if(tmpx < 0) return 0; if(tmpy < 0) return 0; if(tmpx > rectlength) return 0; if(tmpy > rectwidth) return 0; return 1; }
int checkbox(int x, int y, int rectlength, int rectwidth){ if(arr[x][y] == 1) return 1; else return 0; }
int main(){ ios::sync_with_stdio(0); cin.tie(0); int rectlength, rectwidth; cin >> rectlength >> rectwidth;
int x, y, output = 0; char dir;
for(int i=0 ; i<55 ; i++){ for(int j=0 ; j<55 ; j++){ arr[i][j] = 0; } }
while(cin >> x >> y >> dir){ string newdir; cin >> newdir; int dirlen = newdir.size(); for(int i=0 ; i<dirlen ; i++){ if(newdir[i] == 'L'){ if(dir == 'N') dir = 'W'; else if(dir == 'W') dir = 'S'; else if(dir == 'S') dir = 'E'; else if(dir == 'E') dir = 'N'; } else if(newdir[i] == 'R'){ if(dir == 'N') dir = 'E'; else if(dir == 'E') dir = 'S'; else if(dir == 'S') dir = 'W'; else if(dir == 'W') dir = 'N'; } else if(newdir[i] == 'F'){
int tmpx = x, tmpy = y; if(dir == 'N') tmpy += 1; else if(dir == 'E') tmpx += 1; else if(dir == 'W') tmpx -= 1; else if(dir == 'S') tmpy -= 1;
int check = 10; check = checkbound(tmpx, tmpy, rectlength, rectwidth); if(check == 1){ x = tmpx, y = tmpy; }else{ int check2; check2 = checkbox(x, y, rectlength, rectwidth); if(check2 == 0){ cout << x << " " << y << " " << dir << " LOST\n"; arr[x][y] = 1; output = 1; break; } } } } if(output == 0) cout << x << " " << y << " " << dir << endl; output = 0; }
return 0; }
|