Skip to content

Instantly share code, notes, and snippets.

@completejavascript
Created September 15, 2018 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save completejavascript/67851232100de17c82d9cfc685c5a026 to your computer and use it in GitHub Desktop.
Save completejavascript/67851232100de17c82d9cfc685c5a026 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
const int MAX = 1000000;
/**
* Tính độ dài xâu str
*/
int GetLength(char *str)
{
int length = 0;
while(str[length] != '\0') length++;
return length;
}
int main()
{
//freopen("input.txt","r",stdin);
ios::sync_with_stdio(false);
char str[MAX];
while(true)
{
cin >> str;
int length = GetLength(str);
if(length == 1 && str[0] == '*') break;
int len_sub = 1; // Độ dài xâu con T
int N = 0;
while(true)
{
// Duyệt từng độ dài của len_sub và tăng dần lên
if(length % len_sub != 0)
{
len_sub++;
continue;
}
// Kiểm tra xem với độ dài len_sub như vậy có thỏa mãn hay không
int id = 0;
bool check = true;
while(true)
{
if(id + len_sub + 1> length) break;
for(int i = 0; i < len_sub; i++)
{
if(str[i+id] != str[i+len_sub+id])
{
check = false;
break;
}
}
if(check == false) break;
id += len_sub;
}
if(check == true)
{
N = length / len_sub;
break;
}
len_sub++;
}
cout << N << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment