-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMorgan and a String.cpp
70 lines (68 loc) · 1.13 KB
/
Morgan and a String.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
string s1,s2;
int n;
cin>>n;
while(n>0){
cin>>s1>>s2;
vector<char> c1,c2;
int top1=0,top2=0;
for(int i=0;i<s1.size();i++){
c1.push_back(s1[i]);
}
for(int i=0;i<s2.size();i++){
c2.push_back(s2[i]);
}
c1.push_back('z');
c2.push_back('z');
while(top1!=c1.size()-1 && top2!=c2.size()-1){
if(c1[top1]<c2[top2]){
cout<<c1[top1];
top1++;
}
else if(c1[top1]==c2[top2]){
int top_d1=top1,top_d2=top2;
while(c1[top_d1]==c2[top_d2]){
top_d1++;
top_d2++;
}
if(top_d1==c1.size()){
top_d1=top1+1;
top_d2=top2+1;
}
if(c1[top_d1]<c2[top_d2]){
cout<<c1[top1];
top1++;
}
else{
cout<<c2[top2];
top2++;
}
}
else{
cout<<c2[top2];
top2++;
}
}
if(top1!=c1.size()-1){
while(top1!=c1.size()-1){
cout<<c1[top1];
top1++;
}
}
if(top2!=c2.size()-1){
while(top2!=c2.size()-1){
cout<<c2[top2];
top2++;
}
}
cout<<endl;
n--;
}
return 0;
}