forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecretmessage.cpp
48 lines (37 loc) · 860 Bytes
/
secretmessage.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
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
string encode(string s, int size) {
vector<vector<char>> v;
v.resize(size, vector<char>(size));
for(int i = 0; i < size; i++) {
for(int j = 0; j < size; j++) {
v[i][j] = s[(i*size)+j];
}
}
string ret = "";
for(int i = 0; i < size; i++) {
for(int j = size-1; j >= 0; j--) {
char temp = v[j][i];
if(temp != '*') {
ret += temp;
}
}
}
return ret;
}
int main() {
int n;
cin >> n;
for(int i = 0; i < n; i++) {
string s;
cin >> s;
int size = ceil(sqrt(s.length()));
while(s.length() < pow(size, 2)) {
s.push_back('*');
}
cout << encode(s, size) << endl;
}
}