Array ( [0] => [1] => questions [2] => Codevita-Previous-Questions [3] => Alpha-Numeric-Sorting ) Codevita Previous Questions | Alpha Numeric Sorting | THE INQUISITIVE





Alpha Numeric Sorting

LEVEL:Beginner

Description

Given text comprising of words and numbers, sort them both in ascending order and print them in a manner that a word is followed by a number. Words can be in upper or lower case. You have to convert them into lowercase and then sort and print them.

Input Format

First line contains total number of test cases, denoted by N
Next N lines, each contains a text in which words are at odd position and numbers are at even position and are delimited by space
Constraints:
1. Text starts with a word
2. Count of words and numbers are the same.
3. Duplicate elements are not allowed
4. Words should be printed in lower case.
5. No special characters allowed in text.

Output Format

Words and numbers sorted in ascending order and printed in a manner that a word is followed by a number.


Example 1:

Input
2
Sagar 35 sanjay 12 ganesH 53 ramesh 19
Ganesh 59 suresh 19 rakesh 26 laliT 96 
Output
ganesh 12 ramesh 19 sagar 35 sanjay 53 
ganesh 19 lalit 26 rakesh 59 suresh 96 

Example 2:

Input
3
SteveJobs 40 TimBerners-Lee 70 BillGates 45 
JamesGosling 60  LinusTorvalds 35 RichardStallman 54
SatyaNadellea 30 SundarPichai 28 MarkZuckerberg 35 AzimPremji 30
Output
billgates 40 stevejobs 45 timberners-lee 70 
jamesgosling 35 linustorvalds 54 richardstallman 60 
azimpremji 28 markzuckerberg 30 satyanadellea 30 sundarpichai 35
Example 3:

Input
2
Microsoft 78 Google 28 Facebook 34
Oracle 36 Cognizant 73 IBM 67 TCS 63
Output
facebook 28 google 34 microsoft 78 
cognizant 36 ibm 63 oracle 67 tcs 73

oops

Login to see Discussion




Approach

Seggregate the even indices and odd indices to 2 different arrays.
Convert the words into lowecase words.
Sort words and numbers differenlty.
Iterate a loop and print the values alternately.


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution