题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
string str;
getline(cin, str);
if (!str.empty()) {
vector<string> res;
int count = 0;
for (char ch : str) {
if ((count = count % 8) == 0) {
res.emplace_back("");
}
res.back() += ch;
count = count + 1;
}
if (res.back().size() < 8) {
int len=8 - res.back().size();
for (int i = 0; i < len; i++) {
res.back() +="0";
}
}
for_each(res.begin(),res.end(),[](const string& s){
cout<<s<<endl;
});
}
else {
cout<<str;
}
}
#笔试编程题#
