forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMorganandaString.java
46 lines (44 loc) · 1.13 KB
/
MorganandaString.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine();
while(t--!=0){
String a = sc.nextLine();
String b = sc.nextLine();
int l1 = a.length();
int l2 = b.length();
int i=0;
int j=0;
String output="";
while(i<l1&&j<l2){
if(a.charAt(i)<=b.charAt(j)){
output += a.charAt(i);
i++;
}
else{
output += b.charAt(j);
j++;
}
}
if(i<l1){
while(i<l1){
output += a.charAt(i);
i++;
}
}
if(j<l2){
while(j<l2){
output += b.charAt(j);
j++;
}
}
System.out.println(output);
}
}
}