字符串分隔

题目描述

•连续输入字符串,请按长度为8拆分每个字符串后输出到新的字符串数组;
•长度不是8整数倍的字符串请在后面补数字0,空字符串不处理。

输入描述:

连续输入字符串(输入2次,每个字符串长度小于100)

输出描述:

输出到长度为8的新字符串数组

输入例子:
abc
123456789

输出例子:
abc00000
12345678
90000000

 1 #include<iostream>
 2 #include<string>
 3 
 4 using namespace std;
 5 
 6 void display(string str)
 7 {
 8     int count = 0;
 9     int len = str.length();
10     for (int i = 0; i < len; i++)
11     {
12         ++count;
13         if (count>8)
14         {
15             cout << endl;
16             count = 1;
17         }
18         cout << str[i];
19     }
20     for (; count < 8; count++)
21     {
22         cout << 0;
23     }
24     cout << endl;
25 }
26 
27 int main(void)
28 {
29     string str1,str2;
30     cin >> str1 >> str2;
31     display(str1);
32     display(str2);
33 
34 
35     return 0;
36 }
原文地址:https://www.cnblogs.com/hhboboy/p/5517701.html