题解 | #字符串分隔#

字符串分隔

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

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

using namespace std;

int main() {
    string str;
    getline(cin, str);
    if (!str.empty()) {
        vector<string> res;
        int count = 0;
        for (char ch : str) {
            if ((count = count % 8) == 0) {
                res.emplace_back("");
            }
            res.back() += ch;
            count = count + 1;
        }
        if (res.back().size() < 8) {
            int len=8 - res.back().size();
            for (int i = 0; i < len; i++) {
                res.back() +="0";
            }
        }
        for_each(res.begin(),res.end(),[](const string& s){
            cout<<s<<endl;
        });
    }
    else {
        cout<<str;
    }
}


#笔试编程题#
全部评论

相关推荐

01-24 12:50
门头沟学院 C++
投票
菜狗二号:还有啥想的 指定国有行啊,去了就开始幸福美满的生活了,选华子不是折腾自己么,最终财富积累度是差不多的,但是幸福指数是相差甚远的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务