字符串分割

字符串分隔

http://www.nowcoder.com/questionTerminal/d9162298cb5a437aad722fccccaae8a7

#include<iostream>
#include<string>



using namespace std;

const int STR_LEN = 8;

void deal_string(string&);
void full_str(string&, int&);
void unfull_str(string&, int&);

int main()
{
    string str1, str2;
    cin >> str1 >> str2;
    deal_string(str1);
    deal_string(str2);

    return 0;
}


void deal_string(string& str)
{
    int len = str.size();
    int index = 0;
    if (len <= STR_LEN)
    {
        unfull_str(str, index);
        return;
    }

    while (index + STR_LEN < str.size())
    {
        full_str(str, index);
    }

    unfull_str(str, index);
}

//剩余足够字符个数大于等于8时,从index开始,输出8个字符
void full_str(string& str, int& index)
{
    for (int i = index; i < index + STR_LEN; i++)
    {
        cout << str[i];
    }
    index += STR_LEN;
    cout << endl;
}


//剩余字符个数少于8时
void unfull_str(string& str, int& index)
{
    if (index == str.size())
        return;

    int remain = STR_LEN - str.size() + index;
    for (; index < str.size(); index++)
    {
        cout << str[index];
    }

    for (int i = 0; i < remain; i++)
    {
        cout << 0;
    }

    cout << endl;
}
全部评论

相关推荐

宇算唯航:目测实缴资本不超100W的小公司
点赞 评论 收藏
分享
不要停下啊:大二打开牛客,你有机会开卷了,卷起来,去找课程学习,在牛客上看看大家面试笔试都需要会什么,岗位有什么需求就去学什么,努力的人就一定会有收获,这句话从来都经得起考验,像我现在大三了啥也不会,被迫强行考研,炼狱难度开局,啥也不会,找工作没希望了,考研有丝丝机会
点赞 评论 收藏
分享
湫湫湫不会java:先投着吧,大概率找不到实习,没实习的时候再加个项目,然后把个人评价和荣誉奖项删了,赶紧成为八股战神吧,没实习没学历,秋招机会估计不多,把握机会。或者说秋招时间去冲实习,春招冲offer,但是压力会比较大
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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