题解 | #字符串分隔#

字符串分隔

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;
}
全部评论
结构体成员
点赞 回复 分享
发布于 2022-07-02 15:32
a.rem a.quot 大神,请问你的这两个没有定义为什么可以直接使用呢
点赞 回复 分享
发布于 2022-04-12 10:49

相关推荐

2025-11-19 18:44
已编辑
成都理工大学 Java
程序员花海:我面试过100+校招生,大厂后端面试不看ACM,竞赛经历含金量低于你有几份大厂实习 这个简历整体来看不错 可以海投
如何写一份好简历
点赞 评论 收藏
分享
2025-11-26 09:37
山西大学 测试工程师
我要娶个什么名:学长你电脑闹鬼了
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

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