题解 | #字符串分隔#

字符串分隔

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

#include <iostream>
using namespace std;

int main() {
    string s ; 
    while(cin>>s){
        if(s.size() < 8){
            string t(8 - s.size() , '0') ; 
            s+= t ; 
            cout<<s <<endl ; 
        }
        else if(s.size() > 8)
        {
            int n = s.size() / 8 ;
            int i = 0 ;  
            for( ; i < n ;  ++i )
            {   
                string t ; 
                t= s.substr(0 + i * 8 , 8) ; 
                cout<<t <<endl ; 
            }
            if(i * 8 < s.size() ){
                string t = s.substr( i*8 ) ; 
                string tt(8 - t.size() , '0') ; 
                t+= tt ; 
                // cout<<s <<endl ; 
                cout<<t <<endl ; 
            }
        }
        else{
            cout<<s<<endl ; 
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

炫哥_:哥们项目描述里面vector和mysql之类的都要写吗,直接开头技术栈巴拉巴拉就行了,完全不是技术点啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务