题解 | #字符串分隔#

字符串分隔

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")

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

全部评论

相关推荐

不愿透露姓名的神秘牛友
10-29 21:14
疯犬丨哈士奇:喜欢你的人会主动表白,对你有想法的人会很主动,所以要你的公司不会吊着你所以懂了吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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