题解 | #字符串分隔#

字符串分隔

https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7

#include <iostream>
#include <vector>
#include <string>

using namespace std;

vector<string> split_string(const string& str, size_t length) {
    vector<string> result;
    size_t pos = 0;
    while (pos < str.length()) {
        result.push_back(str.substr(pos, length));
        pos += length;
    }

    return result;
}

int main() {
    string str;
    size_t length = 8;
    getline(cin, str);

    while (str.length() % 8 !=0) {
        str.append("0");
    }

    vector<string> parts = split_string(str, length);

    for (const auto& part : parts) {
        cout << part << endl;
    }

    return 0;
}

全部评论

相关推荐

ResourceUtilization:我嘞个董事长
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务