A. You Are Given Two Binary Strings...

图片说明
图片说明

题解

考虑y的最后一个1的位置,需要刚好把它左移到跟x的一个1匹配,如果左移多了,字典序就增加了1,左移少了,就浪费了一些位置可以是0和0匹配从而使得字典序更小

代码

#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug_in  freopen("in.txt","r",stdin)
#define debug_out freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
const ll maxn = 1e6+10;
const ll maxM = 1e6+10;
const ll inf = 1e8;
const ll inf2 = 1e17;

template<class T>void read(T &x){
    T s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    x = s*w;
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}

template <typename ... T>
void DummyWrapper(T... t){}

template <class T>
T unpacker(const T& t){
    cout<<' '<<t;
    return t;
}
template <typename T, typename... Args>
void pt(const T& t, const Args& ... data){
    cout << t;
    DummyWrapper(unpacker(data)...);
    cout << '\n';
}

//--------------------------------------------

int T;
char s1[maxn],s2[maxn];
int len1,len2;
void solve(){
    int cnt = 0,ans = 0;
    for(int i = len2;i>=1;i--){
        if(s2[i] == '0') cnt++;
        else break;
    }
    for(int i = len1-cnt;i>=1;i--){
        if(s1[i] == '0') ans++;
        else break;
    }
    printf("%d\n",ans);
}
int main(){
    // debug_in;

    read(T);
    while(T--){
        scanf("%s",s1+1); len1 = strlen(s1+1);
        scanf("%s",s2+1); len2 = strlen(s2+1);
        solve();
    }


    return 0;
}