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