+ 1
Multiplay
how to make a code with testcase like input : 4a 3c 9o 0 output : aaaacccooooooooo0 input : 11b 3k 9 output : bbbbbbbbbbbkkk9 input : 4bab 18c 12g 7 output : babbabbabbabccccccccccccccccccgggggggggggg7
5 Answers
+ 3
I guess you could start by splitting the input at its spaces. Then you could analyze every item, whether it has length 1 or not. If it's 1, simply print that char. If it's not 1, split this item into the last char and the rest. The last char is the one you want to print, and the rest of the string can be evaluated as an int. Loop this int number of times, and output the char, and finally a space.
+ 1
try this
""""exception may arise if , input is not correct
"""
x=str(input("string :"))
t=x.split()
output=""
for i in t:
if i.isnumeric():
test=int(i)
output+=str(test)
else:
if (len(i)-2)==0:
y=str(int(i[0])*i[1])
else:
y = str(int(i[:(len(i)-1)]) * i[len(i)-1])
output+=y
print(output)
0
def get_part(input):
if len(input) <= 1:
return input
num=int(input.split(input[-1],2)[0])
return num*input[-1]
def get_line(input):
parts=[]
for i in input.split(" "):
parts.append(get_part(i))
return "".join(parts)
n=input()
inputs=[]
inputs.append(n)
for input in inputs:
print(get_line(input))
if i
input : 4bab 18c 12g
outout : bbbbccccccccccccccccccgggggggggggg
how to make it output is
babbabbabbabccccccccccccccccccgggggggggggg
0
@sharique
if i input "4bab"
the program are error.
didnt print "babbabbabbab"
0
this shall be ultimate solution....just write gf4 instead of 4gf....
Hope this helps
""""
instead of writing 454hgjh write hgjh454....and you will be fine
"""
import re
x=str(input("string :"))
t=x.split()
output=""
for i in t:
match = re.match(r"([a-z]+)([0-9]+)", i, re.I)
if match:
items = match.groups()
var=str(items[0]*int(items[1]))
else:
var=i
output+=var
print(output)