题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include <iostream> #include <string> using namespace std; int main() { string str; getline(cin, str); int len = str.length(); if (len % 8 != 0) // 空字符串不处理,不用考虑 { int count = 8 - len % 8; str.append(count, '0'); } len = str.length(); // 更新字符串长度 for (int i = 0; i < len; i += 8) { cout << str.substr(i, 8) << endl; //使用substr(pos,count)分段切割输出 } return 0; }