[华为刷题]分解字符串,string解法

来源:互联网 发布:网络购彩平台贴吧 编辑:程序博客网 时间:2024/06/07 08:12
#include <iostream>#include <vector>#include<string>#include<algorithm>using namespace std;int main() {string s[2];vector<string> result;getline(cin,s[0]);getline(cin, s[1]);for (int i = 0; i < 2; i++){if (s[i].size() <=8){int leng = s[i].size();for (int j = leng; j< 8; j++){s[i].insert(leng,1,'0');}result.push_back(s[i]);}else{int time = s[i].size() / 8;int other = s[i].size() % 8;string temp;for (int m = 0; m < time; m++){temp.assign(s[i].begin() + m * 8, s[i].begin() + m * 8 + 8);result.push_back(temp);}if (other != 0){temp.assign(s[i].begin() + time * 8, s[i].end());int ll = temp.size();temp.insert(ll, 8 - other, '0');result.push_back(temp);}}}for (int i = 0; i < result.size(); i++){cout << result[i] << endl;}return 0;}

原创粉丝点击