题解 | #字符串分隔#

字符串分隔

http://www.nowcoder.com/practice/d9162298cb5a437aad722fccccaae8a7

#include<iostream>
#include<string>
#include<string.h>
using namespace std;

int main()
{
    string str,res;    
    while(cin>>str)
    {
        int mod=str.length()%8;  //取余,余数如果不为零,在后面补上8-mod个0
        int qu=str.length()/8;    //作为后面的循环,本来在这里是+1了,后面发现每次8的整数倍就多一行回车,所以把+1放到有余数的里面,没有余数的只用循环qu次
        auto i=0;
        if(mod!=0)
        {
            while(mod<8)
            {
                str=str+"0";
                mod++;
            }
            qu=qu+1;
        }
        while(qu--)
        {
            
            res=str.substr(0+i*8,8);
            i++;
            for(auto t:res) cout<<t;
            cout<<endl;
        }
    }
}
//strncpy,本来想用这个函数,但是发现C++里面string类这样写不好用,总是出错。

全部评论

相关推荐

02-01 19:48
门头沟学院 Java
神哥了不得:(非引流)直接暑期吧,没时间日常了,老鱼简历把水印去了,或者换个模板,简历字体大小都不太行,建议换2个高质量的项目,面试应该还会再多一些
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务