forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtreasurehunt.cpp
48 lines (44 loc) · 970 Bytes
/
treasurehunt.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
48
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<vector<char>> map;
int i, j;
cin >> i >> j;
map.resize(i);
for(int a = 0; a < i; a++) {
for(int b = 0; b < j; b++) {
char temp;
cin >> temp;
map[a].push_back(temp);
}
}
int x = 0, y = 0, moves = 0;
while(true) {
if(x < 0 || y < 0 || x >= i || y >= j) {
cout << "Out" << endl;
return 0;
}
if(moves > i * j * 2) {
cout << "Lost" << endl;
return 0;
}
if(map[x][y] == 'T') {
cout << moves << endl;
return 0;
}
else if(map[x][y] == 'E') {
y++;
}
else if(map[x][y] == 'W') {
y--;
}
else if(map[x][y] == 'N') {
x--;
}
else if(map[x][y] == 'S') {
x++;
}
moves++;
}
}