输入:
连续输入字符串(输入2次,每个字符串长度小于100)
输出:
输出到长度为8的新字符串数组
样例输入:
abc
123456789
样例输出:
abc00000
12345678
90000000
#include <iostream>
#include <string>
using namespace std;
int main( void )
{
int i = 2;
string line;
while( i-- ){
getline( cin, line );
int nLen = line.length();
int nLenApp = nLen / 8 * 8 + 8;
for( int j = 0; j < nLenApp; ++j ){
if( j % 8 == 0 && j > 0 )
cout << endl;
if( j < nLen )
cout << line[j];
else
cout << '0';
}
cout << endl;
}
return 0;
}
本文介绍了一个使用C++编程语言,通过读取连续输入的字符串,将其转换为长度为8的新字符串数组的过程。通过示例输入和输出,详细解释了如何在程序中应用此逻辑,并提供了完整的源代码实现。
282

被折叠的 条评论
为什么被折叠?



