资源限制
时间限制:1.0s 内存限制:256.0MB
问题描述
给定一个字符串,你需要从第start位开始每隔step位输出字符串对应位置上的字符。
输入格式
第一行一个只包含小写字母的字符串。
第二行两个非负整数start和step,意义见上。
输出格式
一行,表示对应输出。
样例输入
abcdefg
2 2
样例输出
ceg
数据规模和约定
start从0开始计数。
字符串长度不超过100000。
提示
读入上有问题,可以参照字符串进位。
尝试不要出现以下代码:for (int i = 0; i < (int) S.size(); ++i)
————————————————————————————————————————————————
import java.util.Scanner;
public class Main {
static String str;
static int start;
static int step;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
str = sc.next();
start = sc.nextInt();
step = sc.nextInt();
sc.close();
int len = str.length();
while(true) {
System.out.print(str.charAt(start));
if(start + step >= len) break;
start += step;
}
}
}