题解 | 字符串分隔
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include <iostream> #include <string> using namespace std; //先对s最后一组不足八个字符进行“0”补齐,后每八个字符分割。 int main() { string s; getline(cin, s); int a = s.length() % 8; if (a != 0) { for (int b = 0; b < 8 - a; b++) s += '0'; } for (int i = 0; i < s.length() / 8 ; i++) { for (int j = 8 * i; j < 8 * (i + 1); j++) { cout << s[j]; } cout << endl; } return 0; } // 64 位输出请用 printf("%lld")