题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
#include<iostream> #include<string> #include<vector> using namespace std; vector<string> changeStr(const string& str); int main(){ string str; while(cin >> str){ vector<string> res; res = changeStr(str); for(const string& s : res){ cout << s << endl; } } return 0; } vector<string> changeStr(const string& str){ int len = str.size() % 8; if(str.size() < 8){ return {str + string(8 - len, '0')}; } vector<string> res; int i = 0; for(i; i <= str.size() - 8; i+= 8){ res.push_back(str.substr(i, 8)); } if(len != 0){ res.push_back(str.substr(i, str.size() - i) + string(8 - len, '0')); } return res; }