题解 | 添加逗号

添加逗号

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

#include <stdio.h>
#include<string.h>

void reverse(char*str){
    int len=strlen(str);
    for(int i=0;i<len/2;i++){
        char temp=str[i];
        str[i]=str[len-1-i];
        str[len-1-i]=temp;
    }
}
int main() {
    char s[20];
    scanf("%s",s);
    int len=strlen(s);
    reverse(s);

    char res[30]={0};
    int k=0;
    for(int i=0;i<len;i++){
        res[k++]=s[i];
        if((i+1)%3==0&&i!=len-1){
            res[k++]=',';
        }
    }
    reverse(res);
    printf("%s",res);








    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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