Skip to content

Instantly share code, notes, and snippets.

@KirillLykov
Last active December 5, 2016 15:32
Show Gist options
  • Save KirillLykov/bed38d4dd2d0d7a2a222896f7fa19aa5 to your computer and use it in GitHub Desktop.
Save KirillLykov/bed38d4dd2d0d7a2a222896f7fa19aa5 to your computer and use it in GitHub Desktop.
Topcoder 701, 1, div2
#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