Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define endl '\n'
- #define sz(x) int(x.size())
- #define all(x) x.begin(), x.end()
- int main() {
- ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- int testcases;
- cin >> testcases;
- for (int test = 1; test <= testcases; test++) {
- cout << "Case #" << test << ":\n";
- string tmp, s;
- getline(cin >> ws, tmp);
- for (int i = 0; i < sz(tmp); i++) if (isalpha(tmp[i])) s += tmp[i];
- int q = sqrt(sz(s));
- if (q * q == sz(s)) {
- string t[4];
- for (int i = 0; i < q; i++)
- for (int j = 0; j < q; j++)
- t[0] += s[q * i + j];
- for (int i = 0; i < q; i++)
- for (int j = 0; j < q; j++)
- t[1] += s[i + q * j];
- for (int i = q - 1; i >= 0; i--)
- for (int j = q - 1; j >= 0; j--)
- t[2] += s[q * i + j];
- for (int i = q - 1; i >= 0; i--)
- for (int j = q - 1; j >= 0; j--)
- t[3] += s[i + q * j];
- if (t[0] == t[1] && t[1] == t[2] && t[2] == t[3]) {
- cout << q << endl;
- }
- else {
- cout << "No magic :(" << endl;
- }
- }
- else {
- cout << "No magic :(" << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement