#235. 字符串按步长提取字符

    ID: 235 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatWarmup-1gesp3循环结构字符串

字符串按步长提取字符

Extract Every Nth Character

Background

Congcong has recently been learning about string processing. He encountered an interesting task that requires extracting characters from a string at a specific step size.

Problem Description

Given a non-empty string SS and an integer NN, return a new string. This new string is formed by taking characters from the original string SS starting at index 00, and then every NN-th character thereafter. For example, if NN is 33, the new string will contain characters from indices 0,3,6,0, 3, 6, \dots of the original string. NN is guaranteed to be 11 or more.

Input Format

Input is given from Standard Input in the following format.

S N

Where SS is a non-empty string and NN is an integer.

Output Format

Output is printed to Standard Output in the following format.

result_string

Where result_string is the new string extracted according to the rules.

Sample

Miracle
2
Mrce
abcdefg
2
aceg
abcdefg
3
adg

Sample Explanation

For the first sample, the input string is Miracle and N=2N=2. Starting from index 00, characters are extracted every 22 positions, i.e., characters at indices 0,2,4,60, 2, 4, 6. These characters are M, r, c, e respectively, which combine to form Mrce.

Constraints

The length of string SS is between 11 and 10510^5. The integer NN is between 11 and the length of string SS. Time limit: 11 second Memory limit: 10241024 KiB