#include <bits/stdc++.h>

using namespace std;

  

void printString( str, int n)

{

    

    int ones = 0;

    for (int i = 0; i < n; i++)

        if (str[i] == '1')

            ones++;

  

    

    

    bool used = false;

  

    for (int i = 0; i < n; i++) {

        if (str[i] == '' && !used) {

            used = 1;

  

            

            for (int j = 0; j < ones; j++)

                cout << "1";

        }

  

        

        if (str[i] != '1')

            cout << str[i];

    }

  

    

    if (!used)

        for (int j = 0; j < ones; j++)

            cout << "1";

}

  

int main()

{

    string str = "02";

    int n = str.length();

    printString(str, n);

    return 0;

}



Source link
thanks you RSS link
( https://www.geeksforgeeks.org/---string-of-0-1-and-2-with---/)

LEAVE A REPLY

Please enter your comment!
Please enter your name here