•连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组;
•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。
连续输入字符串(输入2次,每个字符串长度小于100)
输出到长度为8的新字符串数组
abc 123456789
abc00000 12345678 90000000
#include<iostream> #include<string> using namespace std; int main() { string str1; string str2; while(cin >> str1) { cin >> str2; int t1=str1.size(); int t2=str2.size(); if(t1%8 != 0) //if not divisible by 8,fill '0' while(t1%8!=0) { str1.push_back('0'); t1++; } if(t2%8 != 0) //if not divisible by 8,fill '0' while(t2%8!=0) { str2.push_back('0'); t2++; } string str=str1+str2; string temp(8,0); int k=0; for(int i=0;i<str.size();i++) { if(k==8) { cout<<temp<<endl; k=0; } temp[k++]=str[i]; } cout<<temp<<endl; } }