Sunday, December 10, 2017

Split String & Sort

An even length string S is passed as the input. The program must split the string into two parts S1 and S2 and sort them in ascending order.

Input Format:
The first line contains S.

Output Format:
Two lines containing S1 and S2 sorted in ascending order.

Boundary Conditions: 2 <= Lenngth of S <= 10000

Example Input/Output 1:
Input:
manage
Output:
age man

Solution:
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
 string s,a[2];
 cin>>s;
 a[0]=s.substr(0,s.size()/2);
 a[1]=s.substr(s.size()/2,s.size());
 sort(a,a+2);
 cout<<a[0]<<endl<<a[1];
}
Share: