题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
// #include <iostream>
// #include <string>
// using namespace std;
// int main() {
// char a;
// string str={};
// int count=0;
// do{
// a = getchar(); // 注意 while 处理多个 case
// if(count!=8){str.append(a.to_string());count+=1;}
// else if(count == 8){str.append(count,a);
// cout<<str<<endl;
// str.clear();
// count = 0;}
// }while(a!='\n');
// int b = str.size();
// cout<<str;
// if(b<8){
// for(int i = 1;i<=8-b;i++)
// {
// count<<0;
// }
// }
// }
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
while (cin >> str) {
while (str.size() > 8) {
cout << str.substr(0, 8) << endl;
str = str.substr(8);
}
str.resize(8, '0');
cout << str << endl;
}
return 0;
}

查看25道真题和解析