def tops(msg:str) -> str:
if msg=='':return ''
try:
x,n=1,5
list_result=[msg[x],]
for i in msg:
list_result.append(msg[x+n])
x,n=x+n,n+4
except IndexError:
return ''.join(list_result[::-1])
def tops(msg: str) -> str:
# your code here
result = []
if msg != result:
i = 1
x = 0
while i <= len(msg):
result.append(msg[i])
x += 1
i += x * 4 + 1
result.reverse()
return "".join(result)
else:
return ""
def tops(msg):
list1 = []
i = 0
j = 0
str2 = ''
while True:
j = j+1
str1 = msg[i:i+j]
i = i + j
if str1 != '' and (j%2)==0:
list1.append(str1)
if str1 == '':
break
for i in list1:
str2 += i[0]
return str2[::-1]
msg1 = 'abcdefghijklmnopqrstuvwxyz12345'
res = tops(msg1)
print(res)
def tops(msg:str) -> str:
# your code here
i = 0
str_len = len(msg)
result = ''
n = 0
if str_len > 0 :
while True:
step = 4*n+3
sub_str = msg[i:i+step]
sub_len = len(sub_str)
if sub_len < step:
sub_str = sub_str + ' '*(step - sub_len)
result = sub_str[len(sub_str)//2] + result
i += step
n += 1
if i > str_len:
break
return result
return ""
// 1 6 15 28 45
// 1 5 9 13 17
// 4 4 4
func tops(s string) string {
var res string
for i, index := 0, 1; index <= len(s); i++ {
res = string(s[index]) + res
index += 1 + 4*(i+1)
}
return res
}