#235. 字符串按步长提取字符
字符串按步长提取字符
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 and an integer , return a new string. This new string is formed by taking characters from the original string starting at index , and then every -th character thereafter. For example, if is , the new string will contain characters from indices of the original string. is guaranteed to be or more.
Input Format
Input is given from Standard Input in the following format.
S N
Where is a non-empty string and 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 . Starting from index , characters are extracted every positions, i.e., characters at indices . These characters are M, r, c, e respectively, which combine to form Mrce.
Constraints
The length of string is between and . The integer is between and the length of string . Time limit: second Memory limit: KiB