题解 | 添加逗号

添加逗号

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

#include <stdio.h>
#include <string.h>
int main() {
    char a[13],b[16]={'0'};
    int w=0,w1;
    scanf("%s", a);
    w=strlen(a);
    if(w<=3) w1=w;
    else if(w<=6) w1=w+1;
    else if(w<=9) w1=w+2;
    else w1=w+3;
    int count=0;
    int j=w1-1;
    for(int i=w-1;i>=0;i--){
        if(count<3){
            count++;
            b[j]=a[i];
            j--;
        }
        else {
            count=0;
            b[j]=',';
            b[j-1]=a[i];
            j-=2;
            count++;
        }//
    }
    b[0]=a[0];
    printf("%s",b);
    return 0;
}

#牛友的春节生活##从夯到拉,锐评职场mentor##春节提前走,你用什么理由请假?##实习到现在,你最困惑的一个问题##备战春招/暑实,现在应该做什么?#
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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