Minimum representation - off more cattle A seventh school

Cerebral palsy as violent, greedy find the smallest string representation of a string of whether the sentence is a minimum representation is violently sentence. .

But can not figure out how complexity is counted. .

#include<bits/stdc++.h>
using namespace std;
#define maxn 205
char s[maxn];
int n;
 
int check(int l,int r){//判断区间[l,r]是否是最小表示法
    int len=r-l+1;
    for(int st=l+1;st<=r;st++){
        int p1=l,p2=st;
        for(int i=0;i<len;i++){
            if(s[p1]<s[p2])break;
            else if(s[p1]>s[p2])return 0;
            ++p1;++p2;
            if(p1>r)p1=l;
            if(p2>r)p2=l;
        }
    }
    return 1;
}
 
int main(){
    int t;cin>>t;
    while(t--){
        scanf("%s",s+1);
        n=strlen(s+1);
        for(int l=1,r;l<=n;l++){
            r=n;
            while(!check(l,r))
                --r;
            for(int i=l;i<=r;i++)cout<<s[i];
            if(r!=n)cout<<" ";
            l=r;
        }
        cout<<'\n';
    }  
}

 

Guess you like

Origin www.cnblogs.com/zsben991126/p/11323627.html