-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy paththere-is-no-spoon1.cpp
59 lines (50 loc) · 1.33 KB
/
there-is-no-spoon1.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
#include <iostream>
#include <vector>
using namespace std;
int main() {
const char EMPTY = '.';
const char NODE = '0';
vector<string> grid;
int width; // the number of cells on the X axis
cin >> width; cin.ignore();
int height; // the number of cells on the Y axis
cin >> height; cin.ignore();
for (int i = 0; i < height; i++) {
string line;
getline(cin, line);
grid.push_back(line);
}
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (grid[y][x] == NODE) {
// node
cout << x << ' ' << y << ' ';
// right neighbor
char neighbor = EMPTY;
for (int neighbor_x = x + 1; neighbor_x < width; neighbor_x++) {
neighbor = grid[y][neighbor_x];
if (neighbor == NODE) {
cout << neighbor_x << ' ' << y << ' ';
break;
}
}
if (neighbor == EMPTY) {
cout << "-1 -1 ";
}
// bottom neighbor
neighbor = EMPTY;
for (int neighbor_y = y + 1; neighbor_y < height; neighbor_y++) {
neighbor = grid[neighbor_y][x];
if (neighbor == NODE) {
cout << x << ' ' << neighbor_y << ' ';
break;
}
}
if (neighbor == EMPTY) {
cout << "-1 -1 ";
}
cout << endl;
}
}
}
}