题解 | #字符串分隔#
字符串分隔
https://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
// HJ4 字符串分隔.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 // #include <iostream> #include<bits/stdc++.h> using namespace std; class Solution { public: void Substr(string& str); }; void Solution::Substr(string& str) { if (str.size() % 8 != 0) { for (int i = 0; i < str.size() % 8; i++) { str.push_back('0'); } } for (int i = 0; i < str.size(); i+=8) { string tmp = ""; tmp = str.substr(i, 8); cout << tmp << endl; } } int main() { Solution a; string str; while (getline(cin,str)) { a.Substr(str); } return 0; }