题解 | #字符串分隔#

字符串分隔

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

#include <cstring>
#include <iostream>
using namespace std;

int main() {
    string str;
    getline(cin,str);
    int N=str.length()/8+1;
    for (int i=0; i<str.length(); i=i+8) {
        if(i==(N-1)*8){
             for (int j=0; j<=7; j++) {
                if(j<=str.length()-8*(N-1)-1){
                    cout<<str[i+j];
                }
                else{
                    cout<<'0';
                }      
            }
            cout<<endl;
        }
        else {
            for (int j=0; j<=7; j++) {
                cout<<str[i+j];
            }
            cout<<endl;
        }
    }
}
// 64 位输出请用 printf("%lld")

获取输入,输入分段,遍历时把握最后一段

全部评论

相关推荐

程序员超好吃:不是,这不是最基本的吗,前端后端测试agent不可能都投啊。别人问你英雄联盟打哪个位置,你说全能,那不就是都不行吗
点赞 评论 收藏
分享
大愣子衰哥:老哥,是正式还是实习
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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