题解 | #字符串分隔#

字符串分隔

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

#include <iostream>
using namespace std;

int main() {
    string a;
    while (cin >> a) { // 注意 while 处理多个 case
        if(a.length() <= 0) continue;

        int num = a.length() % 8;
        if(num > 0) {
            int k = 8 - num;
            for(int i = 0; i < k; ++i) {
                a += '0';
            }
        }

        for(int i = 0; i < a.length(); ++i) {
            cout << a[i];
            if(i % 8 == 7) cout << endl;
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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