题解 | #字符串分隔#

字符串分隔

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

#include <iostream>
#include <string>

using namespace std;

int main() 
{
    string str;
    getline(cin, str);
    int strlen = str.size();
    int n = 8 - (strlen % 8); //用8减去余数计算需要添加多少0
    if ( n == 8){ //当数组长度为八的整数时无需添加0
        n = n -8;
    }
    string zero(n, '0');
    str += zero;//补充0
    
    if(strlen <= 8){
        cout << str << endl;
    }
    else {
    for(int i = 0; i <= strlen/8; i++){
        cout << str.substr(i * 8, 8) << endl;
    }
    }

    return 0;    
}

全部评论

相关推荐

人间雪:简历最好只要一页,除非你牛逼到一页都写不下了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务