forked from DheerajMalisetty/my_hobbies
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode chef.py
More file actions
36 lines (35 loc) · 903 Bytes
/
Copy pathcode chef.py
File metadata and controls
36 lines (35 loc) · 903 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
l=int(input())
for i in range(l):
p=list(input())
x,y=input().split(" ")
x,y=int(x),int(y)
counta=0
countb=0
req=[]
for i in p:
if i=="a":
counta=counta+1
elif i=="b":
countb=countb+1
g=min(counta,countb)
req.append("ab"*g)
counta=counta-g
countb=countb-g
while counta>0 or countb>0:
if counta>0:
for i in range(x):
req.append("a")
counta=counta-1
if counta==0:
break
if counta!=0:
req.append("*")
elif countb>0:
for i in range(y):
req.append("b")
countb=countb-1
if countb==0:
break
if countb!=0:
req.append("*")
print("".join(req))