题解 | #字符串分隔#

字符串分隔

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

#include <string.h>

int main()
{
    int i,cet,count;
    char str[1000]={0},a;
    while(fgets(str, sizeof(str), stdin))//读取字符串
    {
    cet=strlen(str)-1;//获取字符串长度
    if(cet<=8)
    {
        for(i=0;i<8;i++)
        {
            if(i<cet)
            putchar(str[i]);
            else
                putchar('0');
        }
           printf("\n");
    }
        if(cet%8!=0)
      count=(cet/8+1)*8;
        else
            count=cet;
        if(cet>8)
         {
        for(i=0;i<count;i++)
        {
            if(i<cet)
            putchar(str[i]);
            if(i>=cet)
                putchar('0');
            if((i+1)%8==0)
                 printf("\n");
        }
        }
    }
    return 0;
}
全部评论

相关推荐

点赞 评论 收藏
分享
投递华为等公司10个岗位
点赞 评论 收藏
分享
2 1 评论
分享
牛客网
牛客企业服务