forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunhouse.cpp
108 lines (98 loc) · 2.42 KB
/
funhouse.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int w, h;
int count = 1;
while(cin >> w && cin >> h && !(w == 0 || h == 0)) {
// Print header
cout << "HOUSE " << count << endl;
count++;
// Take in house
vector<string> house;
for(int i = 0; i < h; i++) {
string s;
cin >> s;
house.push_back(s);
}
// Find start
int startx, starty;
for(int i = 0; i < h; i++) {
for(int j = 0; j < w; j++) {
if(house[i][j] == '*') {
startx = j;
starty = i;
}
}
}
// Find starting direction
char dir = ' ';
if(startx == 0) {
dir = 'r';
}
if(startx == w-1) {
dir = 'l';
}
if(starty == 0) {
dir = 'd';
}
if(starty == h-1) {
dir = 'u';
}
// Simulate
int currx = startx;
int curry = starty;
while(house[curry][currx] != 'x') {
// Move
if(dir == 'r') {
currx++;
}
if(dir == 'l') {
currx--;
}
if(dir == 'u') {
curry--;
}
if(dir == 'd') {
curry++;
}
// Check if mirror 1
if(house[curry][currx] == '/') {
if(dir == 'r') {
dir = 'u';
}
else if(dir == 'l') {
dir = 'd';
}
else if(dir == 'u') {
dir = 'r';
}
else if(dir == 'd') {
dir = 'l';
}
}
// Check if mirror 2
if(house[curry][currx] == '\\') {
if(dir == 'r') {
dir = 'd';
}
else if(dir == 'd') {
dir = 'r';
}
else if(dir == 'l') {
dir = 'u';
}
else if(dir == 'u') {
dir = 'l';
}
}
}
// Mark last spot
house[curry][currx] = '&';
// Print house
for(auto i : house) {
cout << i << endl;
}
}
}