-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathperiodicstrings.cpp
62 lines (56 loc) · 1015 Bytes
/
periodicstrings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <unordered_set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
ll i, j, k;
ll length;
bool valid = true;
string mainString;
string currString;
string temp;
string temp2;
cin >> mainString;
length = mainString.size();
for (i = 1; i < length; i++)
{
if (length % i == 0)
{
currString = mainString.substr(0, i);
valid = true;
for (j = 1; j < (length / i); j++)
{
temp = "";
temp += currString.substr(i - 1);
temp += currString.substr(0, i - 1);
temp2 = mainString.substr(i*j, i);
if (temp != temp2)
{
valid = false;
}
currString = temp;
}
}
if (valid)
{
cout << i << "\n";
return 0;
}
}
cout << length << "\n";
return 0;
}