HJ4 题解 | #字符串分隔#使用iomnip库

字符串分隔

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

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;

int main() {
    string str;
    cin >> str;
    int len = str.length();
    int group_len = 8; //字符串分割片段长度
    //输出时的参数含义:填充字符0、输出宽度为8、左对齐、输出字符串从i开始8位
    for (int i = 0; i < len; i += group_len) { 
        cout << setfill('0')  << setw(group_len) << left << str.substr(i,group_len) << endl;
    }
    return 0;
}

华为机试刷题实录 文章被收录于专栏

记录一下本科应届生(我自己)刷华为机试题的过程

全部评论

相关推荐

深夜书店vv:腾讯是这样的,去年很多走廊都加桌子当工区
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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