A number is entered, it is necessary to get the minimum by rearranging its digits.
I implemented it, only it works incorrectly for me if the number is 0.
Help to implement, please.
#include <iostream> #include <cstring> using namespace std; void sort(string &s) { for(int a = 1; a < s.length(); a++) { for(int b = s.length() - 1; b >= a; b--) { if(s[b-1] > s[b] && !(s[b] == '0' && b - 1 == 0)) swap(s[b-1], s[b]); } } } int main() { string a; cin >> a; sort(a); cout << a << endl; system("pause"); return 0; }