forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasciifigurerotation.cpp
82 lines (72 loc) · 1.73 KB
/
asciifigurerotation.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
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int n;
bool first = true;
while(cin >> n && n != 0) {
// If not the first time, add a space
if(!first) {
cout << endl;
}
else {
first = false;
}
// Take in data
cin.ignore();
vector<string> v;
for(int i = 0; i < n; i++) {
string temp;
getline(cin, temp);
v.push_back(temp);
}
// Pad strings
int maxlen = 0;
for(auto& i : v) {
int temp = i.length();
maxlen = max(maxlen, temp);
}
for(auto& i : v) {
i.resize(maxlen, ' ');
}
// Create new array
vector<string> rotated;
rotated.resize(maxlen);
for(auto& i : rotated) {
i.resize(n, ' ');
}
// Rotate
for(int i = 0; i < n; i++) {
for(int j = 0; j < maxlen; j++) {
rotated[j][i] = v[i][j];
}
}
// Replace | and -
for(auto& i : rotated) {
for(auto& c : i) {
if(c == '|') {
c = '-';
}
else if(c == '-') {
c = '|';
}
}
}
// Mirror image to be correct
for(auto& i : rotated) {
reverse(i.begin(), i.end());
}
// Strip ending spaces
for(auto& i : rotated) {
while(i[i.size()-1] == ' ') {
i.pop_back();
}
}
// Print
for(auto& i : rotated) {
cout << i << endl;
}
}
}