如果输入的串长是8的倍数,代表可以直接输出,不足的情况下后补0到8的倍数即可,所以我们可以先补0到满足条件,然后8位一输出即可
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 2e5 + 5; int __t = 1, n; void solve() { string s; cin >> s; while (s.length() % 8 != 0) { s += '0'; } for (int i = 0; i < s.length(); i += 8) { cout << s.substr(i, 8) << "\n"; } return; } int32_t main() { #ifdef ONLINE_JUDGE ios::sync_with_stdio(false); cin.tie(0); #endif // cin >> __t; while (__t--) solve(); return 0; }