题解 | #字符串分隔#

字符串分隔

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

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

using namespace std;

void process(vector<string>& res, string& s){
    while(s.size() % 8 != 0){
        s += "0";
    }
    for(int i = 0; i < s.size() - 7; i += 8){
        string tmp = s.substr(i, 8);
        //cout<<tmp<<endl;
        res.push_back(tmp);
    }
}

int main(){
    string str = "";
    vector<string> res;
    
    while(cin>>str){
        process(res, str);
    }
    
    for(int i = 0; i < res.size(); i++){
        cout<<res[i]<<endl;
    }
    
    return 0;
}
华为题库题解 文章被收录于专栏

牛客华为题库的题解

全部评论

相关推荐

点赞 评论 收藏
分享
04-10 08:14
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务