题解 | #字符串分隔#

字符串分隔

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

#include <stdio.h>
#include <string.h>
int main() {
    char input[100],output[9],ch;
    int len=0,i=0,j=0;
    //读取输入字符串
    scanf("%s",input);
    output[8]='\0';
    //获取字符串长度
    len=(strlen(input)%8==0)?strlen(input)/8:strlen(input)/8+1;
    //拆分字符串
    while(i<len){
        strncpy(output, input+8*i,8);

        if((strlen(input)%8!=0)&&i+1==len){
            //当input的字符小于8的时候
            for(j=strlen(input)%8;j<8;j++){
                output[j]='0';
            }
        }
        printf("%s\n",output);
        i++;
    }
    return 0;
}

#华为笔试#
全部评论

相关推荐

01-24 08:13
已编辑
合肥工业大学 Java
程序员牛肉:没啥问题。标准的流水线简历,但是学历好一点,所以应该是有约面的机会的。 这段时间可以考虑把自己的两个项目彻底的理一理。争取能够讲清楚每一个功能点
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务