Split String & Sort
Coding Problem Keys
Split String & Sort
Problem Statement
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 <= Length of S <=10000
Example Input/Output 1
Input
manage
Output
age
man
Note: Max Execution Time Limit: 4000 millisecs
Solution
Programming Language: C++ Language
#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]; }
// Published By PKJCODERS
Programming Language: Python 3 Language
l=input().strip() n=len(l)//2 l=[l[:n],l[n:]] print(*sorted(l),sep='\n')
# Published By PKJCODERS
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments