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

版权声明:【https://github.com/liuchuo】大四在校生,水平有限,还望学长们多多包涵,Github真诚求Star~不甚感激!!!(卖萌脸ヾ(=^▽^=)ノ https://blog.csdn.net/liuchuo/article/details/84257978

问题描述
给定一个字符串,你需要从第start位开始每隔step位输出字符串对应位置上的字符。
输入格式
第一行一个只包含小写字母的字符串。
第二行两个非负整数start和step,意义见上。

输出格式
一行,表示对应输出。
样例输入
abcdefg
2 2

样例输出
ceg
数据规模和约定
start从0开始计数。
字符串长度不超过100000。

提示
读入上有问题,可以参照字符串进位。
尝试不要出现以下代码:for (int i = 0; i < (int) S.size(); ++i)

#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    int star, step;
    cin >> s >>  star >> step;
    for(int i = 0; star+ i * step <= s.size(); i++) 
        cout << s[star + i * step];
    return 0;
}

猜你喜欢

转载自blog.csdn.net/liuchuo/article/details/84257978
今日推荐