【hackerrank】-Day 6: Let's Review

24 篇文章 0 订阅
24 篇文章 0 订阅

30-review-loop
Objective
Today we’re expanding our knowledge of Strings and combining it with what we’ve already learned about loops. Check out the Tutorial tab for learning materials and an instructional video!

Task
Given a string, , of length that is indexed from to , print its even-indexed and odd-indexed characters as space-separated strings on a single line (see the Sample below for more detail).

Note: is considered to be an even index.

Input Format

The first line contains an integer, (the number of test cases).
Each line of the subsequent lines contain a String, .

Constraints

Output Format

For each String (where ), print ‘s even-indexed characters, followed by a space, followed by ‘s odd-indexed characters.

Sample Input

2
Hacker
Rank
Sample Output

Hce akr
Rn ak
Explanation

Test Case 0:

The even indices are , , and , and the odd indices are , , and . We then print a single line of space-separated strings; the first string contains the ordered characters from ‘s even indices (), and the second string contains the ordered characters from ‘s odd indices ().

Test Case 1:

The even indices are and , and the odd indices are and . We then print a single line of space-separated strings; the first string contains the ordered characters from ‘s even indices (), and the second string contains the ordered characters from ‘s odd indices ().


def ss_print(string):
    s_odd = s_even = ''
    for i in range(0,len(string)):
        if i%2 != 0 :
            s_odd = s_odd + string[i]
        else:
            s_even = s_even + string[i]
        i = i + 1
    print(s_even + " " + s_odd)

ii = int(input())
s1 = input()
ss_print(s1)
s2 = input()
ss_print(s2)

Congratulations!

You have passed the sample test cases. Click the submit button to run your code against all the test cases.

Testcase 0
Input (stdin)
2
Hacker
Rank
Your Output (stdout)
Hce akr
Rn ak
Expected Output
Hce akr
Rn ak
AuthorAllisonP
DifficultyEasy
Max Score30
Submitted By155208
NEED HELP?
View tutorial
View discussions
View editorial
View top submissions
RATE THIS CHALLENGE

MORE DETAILS
Download problem statement
Download sample test cases
Suggest Edits

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值