-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnaming.cpp
More file actions
executable file
·63 lines (51 loc) · 839 Bytes
/
naming.cpp
File metadata and controls
executable file
·63 lines (51 loc) · 839 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
string s1, s2;
string s3="", s4="";
cin>>s1>>s2;
sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());
reverse(s2.begin(), s2.end());
int n = s1.length(), i=0, j=0, k=0;
deque<char> a, b;
for(int k=0; k<n; k++) a.push_back(s1[k]);
for(int k=0; k<n; k++) b.push_back(s2[k]);
bool flag=(s1[0]<s2[0]);
for(int i=0; i<n; i++)
{
if(i%2==0)
{
if(!b.empty() && a[0]>=b[0]) flag=true;
if(flag)
{
s4+=a.back();
a.pop_back();
}
else
{
s3+=a.front();
a.pop_front();
}
}
else
{
if(!a.empty() && a[0]>=b[0]) flag=true;
if(flag)
{
s4+=b.back();
b.pop_back();
}
else
{
s3+=a.front();
a.pop_front();
}
}
}
reverse(s4.begin(), s4.end());
s3+=s4;
cout<<s3<<"\n";
return 0;
}