CodeChef Starters 30 Division 4 (Rated) Balanced Reversals Problem Code: BALREV Solution




Problem Link:  https://www.codechef.com/problems/BALREV 

 Solution in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,i,o,z;
    cin>>t;
    while(t--)
    {
        o=z=0;
        cin>>n;
        string str;
        cin>>str;
        for(i=0;i<str.size(); i++)
        {
            if(str[i]=='1')
                o++;
            else
                z++;
        }
        for(i=0;i<z;i++)
        cout<<"0";
        for(i=0;i<o;i++)
        cout<<"1";
        cout<<endl;
    }
}



No comments

Most View Post

Recent post

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.