题解 | #字符串分隔#

字符串分隔

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

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
    char str[100];
    while(scanf("%s",str) != EOF){
        int str_num = strlen(str);
        if(str_num == 0) continue;
        div_t a = div(str_num,8);
        for(int i = str_num; i < (str_num + 8 - a.rem);i++){
            str[i] = '0';     //补位,注意在位数为8的整数倍时会补8位
        }    //(a.rem > 0) 规避输出位数为8的整数倍时多补的8位0
        for(int i = 0;i< a.quot + (a.rem > 0);i++){
            printf("%c%c%c%c%c%c%c%c\n",str[i*8+0],str[i*8+1],str[i*8+2],str[i*8+3],str[i*8+4],str[i*8+5],str[i*8+6],str[i*8+7]);
        }
    }
    return 0;
}
全部评论
a.rem a.quot 大神,请问你的这两个没有定义为什么可以直接使用呢
点赞 回复 分享
发布于 2022-04-12 10:49
结构体成员
点赞 回复 分享
发布于 2022-07-02 15:32

相关推荐

01-26 18:45
门头沟学院 Java
一天代码十万三:哥们实习再包一下吧,产出太笼统了,尽量体现业务
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务