-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·69 lines (54 loc) · 1.14 KB
/
Copy pathsol.cpp
File metadata and controls
executable file
·69 lines (54 loc) · 1.14 KB
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
#include <bits/stdc++.h>
using namespace std;
ostream &operator<<(ostream &os, vector<string> V)
{
for (string s : V)
os << s << endl;
return os;
}
void rotate(vector<string> &V)
{
vector<string> result = V;
int nrows = V.size();
int ncols = V.size();
for (int r = 0; r < nrows; ++r)
{
for (int c = 0; c < ncols; ++c)
{
result[c][ncols - r - 1] = V[r][c];
}
}
V = result;
}
int main()
{
int n;
cin >> n;
while (n--)
{
string s;
cin >> s;
int i = 1;
while (i * i < s.length())
++i;
while (s.length() < i * i)
s += "*";
vector<string> V(i, string(i, ' '));
for (int r = 0; r < i; ++r)
{
for (int c = 0; c < i; ++c)
{
int ci = r * i + c;
V[r][c] = s[ci];
}
}
rotate(V);
// cout << V << endl;
for (int r = 0; r < i; ++r)
for (int c = 0; c < i; ++c)
if (V[r][c] != '*')
cout << V[r][c];
cout << endl;
}
return 0;
}