题解 | #字符串分隔#

字符串分隔

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

#include <iostream>
using namespace std;
int main()
{
    // int lenth=0;
    // char s[100];
    // int num;//需要补0的个数
    // while(cin>>s[lenth])
    // {
    //     if(s[lenth])
    //     {
    //         lenth++;
    //     }
    // };
    // if(lenth%8)
    // {
    //     num =8-(lenth%8);
    // }
    // else
    // {
    //     num = 0;
    // }
    // for(int i = 0;i<num;i++)
    // {
    //     s[lenth++]='0';
    // }
    // for(int i = 1;i<=lenth;i++)
    // {
    //     if(i%8)
    //     {
    //         cout<<s[i-1];
    //     }
    //     else
    //     {
    //         cout<<s[i-1]<<endl;
    //     }
    // }
    int lenth = 0;
    string s;
    cin>>s;
    lenth = s.size();
    int sub;
    if(lenth%8)
    {
        sub = 8-(lenth%8);
    }
    else
    {
        sub=0;
    }
    for(int i =0;i<sub;i++)
    {
        s[lenth++]='0';
    }
    for(int i=1;i<=lenth;i++)
    {
        if(i%8)
        {
            cout<<s[i-1];
        }
        else
        {
            cout<<s[i-1]<<endl;
        }
    }
}

全部评论

相关推荐

10-25 22:20
门头沟学院 Java
代码飞升:同学院本,个人亮点去了,打招呼里面的废话也去了,学院本就是路边一条,明天拉满然后该学还是学,小厂也行尽量先有一段实习。另外你的项目描述写的不好,具体列一下可被提问的点,然后量化一下指标或者收益吧
投了多少份简历才上岸
点赞 评论 收藏
分享
09-25 00:00
已编辑
电子科技大学 Java
球球与墩墩:这不是前端常考的对象扁平化吗,面试官像是前端出来的 const flattern = (obj) => { const res = {}; const dfs = (curr, path) => { if(typeof curr === 'object' && curr !== null) { const isArray = Array.isArray(curr); for(let key in curr) { const newPath = path ? isArray ? `${path}[${key}]` : `${path}.${key}` : key; dfs(curr[key], newPath); } } else { res[path] = curr } } dfs(obj); return res; }
查看3道真题和解析
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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