SuitNdtie

The Repeated String

Apr 21st, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. int main()
  5. {
  6.     char str[5][100010];
  7.     for(int i = 0 ; i < 5 ; i ++){
  8.         scanf("%s",str[i]);
  9.     }
  10.     for(int T = 0 ; T < 5 ; T ++){
  11.         int n = strlen(str[T]);
  12.         int cnt = 0;
  13.         for(int size = 1 ; size <= n ; size ++){
  14.             if(n % size != 0)continue;
  15.            
  16.             int nextcmp = size;
  17.             bool check = true;
  18.             while(nextcmp < n && check){
  19.                 int i;
  20.                 for(i = 0 ; i < size && check; i ++){
  21.                     if(str[T][i] != str[T][i+nextcmp]){
  22.                         check = false;
  23.                     }
  24.                 }
  25.                 nextcmp += size;
  26.             }
  27.             if(check){
  28.                 cnt++;
  29.             }
  30.         }
  31.         printf("%d\n",cnt);
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment