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; }
华为机试刷题实录 文章被收录于专栏
记录一下本科应届生(我自己)刷华为机试题的过程