Thursday, March 3, 2022

 HackerRank 30 Day Code Challenge(Day 6)

Problem:

Taking n input strings, separate each string's odd and even indexes and print the even-odd characters in form of two space-separated strings on a single line.

n=int(input())
x=0
evenstr=""
oddstr=""
i=0
for x in range(0,n):
s=input()
evenstr = ""
oddstr = ""

for i in range(0, len(s)):
if i % 2 == 0:
evenstr = evenstr + s[i]
elif i % 2 != 0:
oddstr = oddstr + s[i]
print(evenstr +' '+ oddstr )




No comments:

Post a Comment