Advertisement
a53

SubStringRep

a53
Sep 14th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. char s[1001],sb[1001],v[100001],aux[100001];
  4. unsigned int n,i,l,j,gasit;
  5.  
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(0);
  10. cin>>n;
  11. while(n--)
  12. {
  13. cin>>s;
  14. l=strlen(s);
  15. gasit=0;
  16. for(i=1;i<=l/2&&gasit==0;++i)
  17. {
  18. if(l%i==0)
  19. {
  20. strcpy(sb,s);
  21. sb[i]='\0';
  22. if(strcmp(sb,s+(l-i))==0)
  23. {
  24. strcpy(v, sb);
  25. while(strlen(v)<l)
  26. strcpy(aux,v),strcat(v,aux);
  27. v[l]='\0';
  28. if(strcmp(v,s)==0)
  29. gasit=1;
  30. }
  31. }
  32. }
  33. if(gasit==1)
  34. cout<<sb;
  35. else
  36. cout<<-1;
  37. cout<<'\n';
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement