Codeforces Round #787 (Div. 3) 1675C. Detective Task Solution



Problem Link:  https://codeforces.com/problemset/problem/1675/C

Solve in C++:  

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int cn=0,f=0,sz,i,j;
        string s,sc;
        cin>>s;
        sc=s;
        sz=s.size();
        sort(s.begin(),s.end());
        if(s[0]==s[sz-1])
        {
            if(s[0]=='?')
                cout<<sz<<endl;
            else
                cout<<"1"<<endl;
        }
        else
        {
            f=0;
            for(i=0; i<sz; i++)
            {
                if(sc[i]=='0')
                {
                    f=1;
                    for(j=i; j>=0; j--)
                    {
                        cn++;
                        if(sc[j]=='1')
                            break;
                    }
                    break;

                }
            }
            if(f==0)
            {
                for(i=sz-1; i>=0; i--)
                {
                    cn++;
                    if(sc[i]=='1')
                        break;
                }
            }
            cout<<cn<<endl;
        }
    }
}

 





No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.