字符串分隔

Posted hhboboy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串分隔相关的知识,希望对你有一定的参考价值。

题目描述

•连续输入字符串,请按长度为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 }

 

以上是关于字符串分隔的主要内容,如果未能解决你的问题,请参考以下文章

字符串分隔

SQL Server 的逗号分隔输入字符串

华为机试题-字符串分隔

华为机试:字符串分隔

C - 分隔输入流中的字符串

Laravel 验证 - 逗号分隔的字符串输入为数组