蓝桥杯--算法提高 字符串跳步

问题描述
给定一个字符串,你需要从第start位开始每隔step位输出字符串对应位置上的字符。
输入格式
第一行一个只包含小写字母的字符串。
第二行两个非负整数start和step,意义见上。
输出格式
一行,表示对应输出。
样例输入
abcdefg
2 2
样例输出
ceg
数据规模和约定
start从0开始计数。
字符串长度不超过100000。
提示
读入上有问题,可以参照字符串进位。
尝试不要出现以下代码:for (int i = 0; i < (int) S.size(); ++i)

#include<iostream>
#include<cstring>
using namespace std;
char a[100];
void f(int star,int step)
{
	cout<<a[star];
	if((star+step)>=strlen(a))
	return;
	f(star+step,step);
}
int main()
{
	int star,step;
	cin>>a>>star>>step;
	f(star,step);
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/WILDCHAP_/article/details/107425811