Vị trí zero cuối cùng

Cách 3
 avatar
tocdovodoi
plain_text
2 months ago
472 B
2
Indexable
Never
#include<bits/stdc++.h>
using namespace std;
string s;
int dau,giua,cuoi;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    getline(cin,s);
    dau=0;cuoi=s.length();
    while(dau<cuoi)
    {
        giua=(dau+cuoi+1)/2;
        if(s[giua]=='1')
        {
            dau=dau;
            cuoi=giua-1;
        }
        if(s[giua]=='0')
        {
            dau=giua; 
            cuoi=cuoi;
        }
    }
    cout<<dau+1;
}
Leave a Comment