手头的任务:
Given a string, S, of length N that is indexed from 0 to N-1, print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line.
The test cases are written such that The first line contains an integer, N (the number of test cases). Each line i of the N subsequent lines contain a String.
这是我的代码:
N = int(raw_input())
for i in range(0,N):
string = raw_input()
evenlist = []
oddlist = []
for item, char in enumerate(strg):
if item % 2 == 0:
evenlist.append(char)
else:
oddlist.append(char)
print ''.join(evenlist), ''.join(oddlist)
样本运行:
The first input is:
2
Hacker
Rank
Expected output is:
Hce akr
Rn ak
但我得到:
HceRn akrak
这里有一个指向assignment的链接,可以更好地解释这个问题。
目前没有回答
相关问题 更多 >
编程相关推荐