蜗蜗的二进制日志

题目传送门

这个题目是一个找规律题目

结论一:答案不会超过3长度

可以列举出来所有长度为四的都能化成长度小于三的

结论二:答案只有六种

1.如果字符串全是0,答案就是0
2.如果字符串全是1,答案是1
3.如果字符串首位是0,末位是1,答案就是01
4.如果字符串首位是1,末尾是0,答案就是10
5.如果字符串头尾都是0,答案就是010
6.答案就是101

代码如下

#include<bits/stdc++.h>
using namespace std;

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define endl '\n';

void gmin(int &x,int y){x=min(x,y);}
void gmax(int &x,int y){x=max(x,y);}
string pt(int st,bool x){return st==1?x?"Yes":"No":x?"YES":"NO";}

char s[200005];
int n;

bool match(int x,int y){
    if(s[1]!='#'&&s[1]-'0'!=x) return 0;
    if(s[n]!='#'&&s[n]-'0'!=y) return 0;
    return 1;
}

void solve(){  
    cin>>s+1;
    n=strlen(s+1);
    bool o=1,z=1;
    for(int i=1;i<=n;i++){
        if(s[i]=='#') continue;
        o&=(s[i]-'0'==1);
        z&=(s[i]-'0'==0);
    }
    if(o) cout<<"1";
    else if(z) cout<<"0";
    else if(match(1,0)) cout<<"10";
    else if(match(0,1)) cout<<"01";
    else if(match(0,0)) cout<<"010";
    else cout<<"101";
    cout<<endl;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int t=1;
    cin>>t;
    while(t--) solve();
}
posted @ 2026-01-24 11:58  zhangruotian_Max  阅读(0)  评论(0)    收藏  举报