-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy paththere-is-no-spoon-episode-1.cpp
70 lines (59 loc) · 2.05 KB
/
there-is-no-spoon-episode-1.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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
/**
* Don't let the machines win. You are humanity's last hope...
**/
int main()
{
int width; // the number of cells on the X axis
int height; // the number of cells on the Y axis
string l_return; // output
map<int, vector<int> > nodesMap;
cin >> width; cin.ignore(); cin >> height; cin.ignore();
for (int i = 0; i < height; i++)
{
string line; // width characters, each either 0 or .
getline(cin, line);
int l_cmpt = 0;
for(string::iterator it = line.begin(); it != line.end(); ++it)
{
if( *it == '0' ) nodesMap[i].push_back(l_cmpt);
++l_cmpt;
}
}
for(int i = 0; i < height; i++)
{
if( nodesMap.find(i) != nodesMap.end() )
{
for( int j = 0; j < nodesMap[i].size(); j++)
{
int l_current = nodesMap[i][j];
l_return = to_string(l_current) + " " + to_string(i);
if (j == nodesMap[i].size() -1) l_return += " -1 -1";
else l_return += " " + to_string( nodesMap[i][j+1]) + " " + to_string(i);
bool l_found = false;
for( int k = i +1; k < height; ++k)
{
if( nodesMap.find(k) != nodesMap.end() )
{
if( find(nodesMap[k].begin(), nodesMap[k].end(), l_current) != nodesMap[k].end() )
{
l_return += " " + to_string(l_current) + " " + to_string(k);
l_found = true;
break;
}
}
}
if(!l_found)
{
l_return += " -1 -1";
}
cout << l_return << endl;
}
}
}
}