forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnectthedots.cpp
112 lines (100 loc) · 2.66 KB
/
connectthedots.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
109
110
111
112
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void process(vector<string>& v) {
vector<pair<int, int>> locations(62);
int size = 0;
for(int i = 0; i < v.size(); i++) {
for(int j = 0; j < v[i].size(); j++) {
if(isdigit(v[i][j])) {
size++;
locations[v[i][j]-'0'] = {i,j};
}
if(isalpha(v[i][j])) {
size++;
if(islower(v[i][j])) {
locations[v[i][j]-'a'+10] = {i,j};
}
else {
locations[v[i][j]-'A'+36] = {i,j};
}
}
}
}
for(int i = 1; i < size; i++) {
pair<int, int> p1 = locations[i-1];
pair<int, int> p2 = locations[i];
// HORIZONTAL
if(p1.first == p2.first) {
int j = p1.first;
// BACKWARD
if(p1.second > p2.second) {
for(int i = p1.second-1; i > p2.second; i--) {
if(v[j][i] == '|') {
v[j][i] = '+';
}
if(v[j][i] == '.') {
v[j][i] = '-';
}
}
}
// FOREWARD
else {
for(int i = p1.second+1; i < p2.second; i++) {
if(v[j][i] == '|') {
v[j][i] = '+';
}
if(v[j][i] == '.') {
v[j][i] = '-';
}
}
}
}
// VERTICAL
else {
int j = p1.second;
// UP
if(p1.first > p2.first) {
for(int i = p1.first-1; i > p2.first; i--) {
if(v[i][j] == '-') {
v[i][j] = '+';
}
if(v[i][j] == '.') {
v[i][j] = '|';
}
}
}
// DOWN
else {
for(int i = p1.first+1; i < p2.first; i++) {
if(v[i][j] == '-') {
v[i][j] = '+';
}
if(v[i][j] == '.') {
v[i][j] = '|';
}
}
}
}
}
// Print array
for(auto s : v) {
cout << s << endl;
}
}
int main() {
vector<string> v;
string s;
while(getline(cin, s)) {
if(s == "") {
process(v);
v.clear();
cout << endl;
}
else {
v.push_back(s);
}
}
process(v);
}