题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<string> split_string(const string& str, size_t length) {
vector<string> result;
size_t pos = 0;
while (pos < str.length()) {
result.push_back(str.substr(pos, length));
pos += length;
}
return result;
}
int main() {
string str;
size_t length = 8;
getline(cin, str);
while (str.length() % 8 !=0) {
str.append("0");
}
vector<string> parts = split_string(str, length);
for (const auto& part : parts) {
cout << part << endl;
}
return 0;
}