-
Notifications
You must be signed in to change notification settings - Fork 6
/
BotSavesPrincess.cpp
47 lines (34 loc) · 1.01 KB
/
BotSavesPrincess.cpp
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
#include <iostream>
#include <vector>
using namespace std;
/* Head ends here */
void displayPathtoPrincess(int n, vector <string> grid){
int mX = 0, mY = 0, pX = 0, pY = 0;
string currentString = "";
for(int y = 0; y < n; y++){
currentString = grid[y];
for(int x = 0; x < n; x++){
if(currentString[x] == 'm'){mX = x; mY = y;}
else if(currentString[x] == 'p'){pX = x; pY = y;}
else {continue;}
}
}
string xDirection = "RIGHT\n"; int xDiff = pX - mX;
if(xDiff < 0){xDirection = "LEFT\n"; xDiff = - xDiff;}
while(--xDiff >= 0){cout << xDirection;}
string yDirection = "DOWN\n"; int yDiff = pY - mY;
if(yDiff < 0){yDirection = "UP\n"; yDiff = - yDiff;}
while(--yDiff >= 0){cout << yDirection;}
}
/* Tail starts here */
int main(void) {
int m;
vector <string> grid;
cin >> m;
for(int i=0; i<m; i++) {
string s; cin >> s;
grid.push_back(s);
}
displayPathtoPrincess(m,grid);
return 0;
}