forked from shauryas1ngh/codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSKMP.cp
More file actions
116 lines (100 loc) · 1.71 KB
/
SKMP.cp
File metadata and controls
116 lines (100 loc) · 1.71 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include<bits/stdc++.h>
#define pi 3.14159265359
#define ll long long
#define wh(t) int t;cin>>t; while(t--)
#define speed ios::sync_with_stdio(0); cin.tie(0);
#define endl "\n"
#define f(i,a,b) for(int i=a;i<b;i++)
using namespace std;
#include<string.h>
//aditya ranaut- phoenix_aditya
void solve()
{
string s, p;
cin>>s;
cin>>p;
set<char> letters;
map<char,int> count;
for(char x: s)
{
letters.insert(x);
if(!count[x])
count[x]=1;
else
count[x]++;
}
bool character=false;
for(char x: p)
{
count[x]--;
}
for(int i=0;i<p.size()-1;i++)
{
if(p[i+1]>p[i])
character=true;
}
string ans1="";
string ans2="";
for(auto z: letters)
{
if(z==p[0])
{
ll k=count[z];
while(k>0)
{
ans2+=z;
k--;
}
ans2+=p;
ans1+=p;
while(count[z]>0)
{
ans1+=z;
count[z]--;
}
}
while(count[z]>0)
{
ans1+=z;
ans2+=z;
count[z]--;
}
}
// for(auto x: count)
// {
// cout<<x.first<<" "<<x.second<<endl;
// }
if(ans1>ans2)
cout<<ans2<<endl;
else
cout<<ans1<<endl;
}
int main()
{
speed;
wh(t)
{solve();}
return 0;
}
/*
3
akramkeeanany
aka
supahotboy
bohoty
daehabshatorawy
badawy
1
zetaabcdefghijklmnopqrstuvwx
zeta
2
aaaabbbbc
ba
aaaabbbbc
bc
*/
/*
aaakaeekmnnry
abohotypsu
aabadawyehhorst
*/