Last active
September 16, 2018 16:26
-
-
Save WindAzure/d0107b7bb2416d71ee0b62d96861e4a1 to your computer and use it in GitHub Desktop.
UVa 455
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 <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