题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
/*
借鉴了一个让我耳目一新的解法,string.append同样字符不用循环,二是分隔字符串的做法
*/
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
cin >> str;
// 如果模8不等于0,则补零
if (str.size() % 8 != 0) {
str.append(8 - str.size() % 8, '0');
}
for (int i = 0; i < str.size(); i += 8) {
cout << str.substr(i, 8) << endl;
}
return 0;
}
查看28道真题和解析