题解 | 字符串分隔

字符串分隔

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

#include <iostream>
#include <string>
using namespace std;
//先对s最后一组不足八个字符进行“0”补齐,后每八个字符分割。
int main()
{
    string s;
    getline(cin, s);
    int a = s.length() % 8;
    if (a != 0)
    {
        for (int b = 0; b < 8 - a; b++)
            s += '0';
    }
    for (int i = 0; i < s.length() / 8 ; i++)
    {
        for (int j = 8 * i; j < 8 * (i + 1); j++)
        {
            cout << s[j];
        }
        cout << endl;
    }
    return 0;


}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

06-23 11:28
门头沟学院 Java
牛客91966197...:也有可能是点拒绝的时候自动弹的话术
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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