Last active
December 5, 2016 15:32
-
-
Save KirillLykov/bed38d4dd2d0d7a2a222896f7fa19aa5 to your computer and use it in GitHub Desktop.
Topcoder 701, 1, div2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
class SquareFreeString { | |
public: | |
string isSquareFree(string s) { | |
if (s.length() < 2) | |
return "square-free"; | |
for (int l = 2; l <= s.length(); l += 2) { | |
for (int shift = 0; shift < s.length() - l + 1; ++shift) { | |
bool res = true; | |
for (int i = 0; i < l/2; ++i) { | |
res = res && (s[shift + i] == s[shift + i+l/2]); | |
//cout << l << shift << i <<"| " <<shift + i << " " << shift + 2*i+l/2 << "| " << s[shift + i] << " " << s[shift + i+l/2] << "AA\n"; | |
} | |
if (res) | |
return "not square-free"; | |
} | |
} | |
return "square-free"; | |
} | |
}; | |
int main(int, char**) { | |
SquareFreeString sq; | |
string s; | |
cin >> s; | |
cout << sq.isSquareFree(s); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment