Subscribe Us

Responsive Advertisement

Advertisement

1398B codeforces solution in cpp

 1398B codeforces solution in cpp

by ujjal roy



#include<bits/stdc++.h>

using namespace std;

main()

{

    int t,i;

    cin>>t;

    while(t--)

    {

        vector<int> v;

        int c=0,sum=0,co=0;

        string s;

        cin>>s;

        for(i=0;i<s.size();i++)

        {

            if(s[i]=='1') c++;

            else if(c>0)

            {

                co++;

                v.push_back(c);

                c=0;

            }

        }

        if(c>0)   v.push_back(c);


        sort(v.begin(),v.end());

        for(i=v.size()-1;i>=0;i=i-2)

        {


            sum+=v[i];

        }

        cout<<sum<<endl;

    }

    return 0;

}


Post a Comment

0 Comments