码迷,mamicode.com
首页 > 其他好文 > 详细

数字的标准写法

时间:2019-09-17 22:46:36      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:har   div   bsp   include   using   一个   a+b   char   ==   

    #include <bits/stdc++.h>
    using namespace std;
    #define ll long  long 
    char s[20],p[20];
    int cnt;
    void solve(ll c){
        if(c<0){    
        printf("-");
        c=abs(c);
    }
          cnt  = 0;
        while(c){//为0呢 
            s[cnt++] = char(c%10)+0;
            c/=10;
        }
        for(int i =0;i<cnt/2;i++){
            p[i] = s[i];
            s[i]  =s[cnt-1-i];
            s[cnt-1-i] = p[i];
        }
        for(int i =0;i<cnt;i++){
            printf("%c",s[i]);
            int x =cnt-1-i;
            if(x%3==0&&i!=cnt-1){//数字的标准写法,要从后往前每3个一个, 
                printf(",");
            }
        }
    }
    int main()
    {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        if(a+b==0){
            printf("0\n");
        }
        else
        solve(a+b);
        return 0;
    }
    
        

 

数字的标准写法

标签:har   div   bsp   include   using   一个   a+b   char   ==   

原文地址:https://www.cnblogs.com/tingtin/p/11537358.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!