题解 | #字符串分隔#

字符串分隔

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

// #include <iostream>
// #include <string>
// using namespace std;
// int main() {
//     char a;
//     string str={};
//     int count=0;
    
//     do{
//         a = getchar(); // 注意 while 处理多个 case
//         if(count!=8){str.append(a.to_string());count+=1;}
//         else if(count == 8){str.append(count,a);
//         cout<<str<<endl;
//         str.clear();
//         count = 0;}
//     }while(a!='\n');
//     int b = str.size();
//     cout<<str;
//     if(b<8){
//         for(int i = 1;i<=8-b;i++)
//             {
//                 count<<0;
//             }
//     }
// }
#include <iostream>
#include <string>

using namespace std;

int main() {
  string str;
  while (cin >> str) {
    while (str.size() > 8) {
      cout << str.substr(0, 8) << endl;
      str = str.substr(8);
    }
    str.resize(8, '0');
    cout << str << endl;
  }
  return 0;
}

全部评论

相关推荐

04-21 13:50
已编辑
北京理工大学 硬件测试
我们学校连夜发了声明,绝了绝了!看完了全部ppt,震碎三观。一般情况下我是站学生的,但这不是一般情况。这男的不能被取消学位吗?自己吃到了红利,靠着面试泄题得到的保研,又反手举报导师。这导师是《被举报系列》里最惨最恋爱脑的了,当然最可怜的是他的同妻……
牛客小黄鱼:看了ppt的聊天记录,真不知道谁才是受害者!有人为你剥过柚子吗?有人为你雪地里等你吗?有人为你写过情书吗?有人为你规划未来吗?有人为你小心翼翼吗?有人为你整页失眠失眠吗? 有人为你送上自己的科研成果吗?有人为你安排出国留学吗?有人愿意给你一个月2万吗?
点赞 评论 收藏
分享
03-25 19:00
东北大学 Java
程序员牛肉:太好了,是聊天记录。不得不信了。 当个乐子看就好,不要散播焦虑
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务