题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
1.输入
while(cin>>str)
2.思路
先计算会输出多少字符串,然后for第一层循环
再for循环8次
输出str[m]或‘0’;
当增量m满足小于str的大小时,输出str[m]
否则输出‘0’
3.代码
#include<iostream>
#include<string>
#include<vector>
#include</vector></string></iostream>
using namespace std;
int main()
{
string str;
int m = 0;
while(cin>>str)
{
int k = (str.size()-1)/8+1;
m = 0;
for(int i = 0;i<k;i++)
{
for(int j = 0;j<8;j++)
{
if(m<str.size())
cout<<str[m];
else
cout<<'0';
m++;
}
cout<<endl;
}
}
}

