UVa 11452 - Dancing the Cheeky-Cheeky Solution

#include <iostream>
#include <string>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--){
        ws(cin);
        string s;
        cin>>s;
        int n=s.size();
        int len=n/3+1;
        if(len<1)
            len=1;
        string ans;
        while(len<=n/2){
            string tmp=s.substr(n-len,len);
            if(tmp==s.substr(n-2*len,len))
                ans=tmp;
            len++;
        }
        for(int i=0;i<8;i++)
            cout<<ans[i%ans.size()];
        cout<<"..."<<endl;
    }
}

Comments