Skip to content

Instantly share code, notes, and snippets.

@WindAzure
Last active September 16, 2018 16:26
Show Gist options
  • Select an option

  • Save WindAzure/d0107b7bb2416d71ee0b62d96861e4a1 to your computer and use it in GitHub Desktop.

Select an option

Save WindAzure/d0107b7bb2416d71ee0b62d96861e4a1 to your computer and use it in GitHub Desktop.
UVa 455
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
bool isStrComposeByBasisStr(string &str, string & basisStr, int period)
{
auto strLen = str.size();
for (auto index = period; index < strLen; index += period)
{
auto periodStr = str.substr(index, period);
if (basisStr != periodStr)
{
return false;
}
}
return true;
}
int main()
{
auto T = 0;
auto str = string{};
scanf("%d", &T);
for (auto t = 0; t < T; t++)
{
if (t != 0) getchar();
cin >> str;
auto strLen = str.size();
for (auto period = 1; period <= strLen; period++)
{
if (strLen % period == 0)
{
auto basisStr = str.substr(0, period);
if (isStrComposeByBasisStr(str, basisStr, period))
{
printf("%d\n", period);
break;
}
}
}
if (t != T - 1) printf("\n");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment