B. Binary Period(水、Educational Codeforces Round 86 (Rated for Div. 2))

B. Binary Period

CF 1342B

Meaning: given string ttt , the output stringsss ∣ s ∣ |s| | S | length less2 ⋅ | t | 2 · |2t ), such thatssThe period in s is the smallest.

Idea: Judge ttWhether there are0, 1 0, 1 in t at the same time01

  • If single, the minimum period is 1 11 : Direct output
  • If there are 0, 1 0, 1 at the same time0 , 1 , the minimum period is2 22 : Output01 010 1 interval string
int n;
int main(){
    
    
    int t,tt,f1=0,f0=0,len;
    LL x,a,b,y,ans;
    cin>>t;
    string s;
    while(t--){
    
    
        cin>>s;
        f1=0;f0=0;
        len=s.length();
        for(int i=0;i<len;i++){
    
    
            if(s[i]-'0')f1++;
            else f0++;
        }
        if(f1==0){
    
    
            for(int i=1;i<=len;i++)
                cout<<"0";
            cout<<endl;
            continue;
        }
        if(f0==0){
    
    
            for(int i=1;i<=len;i++)
                cout<<"1";
            cout<<endl;
            continue;
        }
        if(s[0]=='0'){
    
    
            for(int i=0;i<len;i++){
    
    
                cout<<"01";
            }
            cout<<endl;
            continue;
        }
        if(s[0]=='1'){
    
    
            for(int i=0;i<len;i++){
    
    
                cout<<"10";
            }
            cout<<endl;
            continue;
        }
    }
}

Guess you like

Origin blog.csdn.net/weixin_44986601/article/details/105829278