题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
利用数学表达式求余,补充末尾0,然后substr分割输出。
#include <bits/stdc++.h>
using namespace std;
int main(){
    string str;
    getline(cin, str);
    int index = str.length();
    int addZero = 8 - index % 8;
    while (addZero > 0 && addZero < 8)
    {
        str += '0';
        addZero--;
    }
    while (str.length() > 0)
    {
        cout << str.substr(0, 8) << endl;
        str = str.substr(8);
    }
}
 基恩士成长空间 421人发布
基恩士成长空间 421人发布 查看9道真题和解析
查看9道真题和解析