Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- char s[1001],sb[1001],v[100001],aux[100001];
- unsigned int n,i,l,j,gasit;
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cin>>n;
- while(n--)
- {
- cin>>s;
- l=strlen(s);
- gasit=0;
- for(i=1;i<=l/2&&gasit==0;++i)
- {
- if(l%i==0)
- {
- strcpy(sb,s);
- sb[i]='\0';
- if(strcmp(sb,s+(l-i))==0)
- {
- strcpy(v, sb);
- while(strlen(v)<l)
- strcpy(aux,v),strcat(v,aux);
- v[l]='\0';
- if(strcmp(v,s)==0)
- gasit=1;
- }
- }
- }
- if(gasit==1)
- cout<<sb;
- else
- cout<<-1;
- cout<<'\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement