how to sort string containing numbers in c 2b 2b

Solutions on MaxInterview for how to sort string containing numbers in c 2b 2b by the best coders in the world

showing results for - "how to sort string containing numbers in c 2b 2b"
Aoibheann
10 Feb 2016
1#include <iostream>
2#include <bits/stdc++.h> 
3#include<string>
4using namespace std; 
5int main() {
6   string s="4321";
7   int a[s.length()];
8  for(int i=0;i<s.length();i++){
9    a[i]=s[i]-48;
10   }
11  sort(a,a+s.length());
12for(int i=0;i<s.length();i++){
13    cout<<a[i];
14   }
15    return 0;
16}
17