题解 | #字符串分隔#
字符串分隔
http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7
C++实现字符串分割,代码如下:
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
while(getline(cin, str))
{
int len=str.size(); //字符串长度
int index=len%8; //长度除8取余数
while(index<8&&index!=0) //补齐字符串使其被8整除
{
str[len++]='0';
++index;
}
for(int i=0;i<len;++i) //字符串每8个遍历
{
cout<<str[i];
if((i+1)%8==0) cout<<endl;
}
}
return 0;
} 
查看17道真题和解析