题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include <iostream>
#include <vector>
using namespace std;
int main() {
string s;
getline(cin,s);
if(s == ""){
cout <<s;
}
if(s.length() % 8 != 0){//字符串不为8的整数倍
for(int i = 1; i <=s.length()/8 + 1;i++){
if(i*8 < s.length()){
for(int j = (i-1)*8; j < i*8;j++){
cout << s[j];
}
cout << endl;
}
else{
for(int j = (i - 1) * 8; j < s.length(); j++){
cout <<s[j];
}
for(int j = 0; j < i*8 - s.length();j++){
cout <<"0";
}
cout << endl;
}
}
}
else{//字符串为8的整数倍
for(int i = 0; i < s.length()/8;i++){
for(int j = i*8; j < i*8+8; j++){
cout << s[j];
}
cout <<endl;
}
}
}
// 64 位输出请用 printf("%lld")