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 |
#include <iostream> #include <algorithm> #include <queue> #include <vector> #include <cstdlib> #include <cstdio> #include <string> #include <cstring> #include <ctime> #include <iomanip> #include <cmath> #include <set> using namespace std; int main(int argc, char *argv[]) { char str[1000005]; while (scanf(" %s",str) != EOF) { int len = strlen(str); if(len == 1 && str[0] == '.') break; for (int i = 1;i <= len;i++) { if (len % i != 0){ continue; }else{ string t; for (int j = 0;j < i;j++) { t += str[j]; } int cur = 0; bool flag = true; while (cur < len) { if(!flag) break; for (int j = 0;j < i;j++) { if(str[cur] == t[j]){ cur++; continue; }else{ flag = false; break; } } } if(flag) { cout << len/i << endl; break; } } } } return 0; } |
暴力就行,不用想多了
然后因为是单调性的问题,注意剪枝,不要傻得乎的都判断了。