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

PAT (Advanced Level) 1001. A+B Format (20)

时间:2016-05-15 21:23:24      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

简单题。

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

int a,b,tot,cnt;
int u[20];
char ans[100];

int main()
{
    while(~scanf("%d%d",&a,&b))
    {
        a=a+b;
        if(a==0)
        {
            printf("0\n");
            continue;
        }
        int tmp=abs(a);
        tot=0,cnt=0;
        while(tmp) u[tot++]=tmp%10,tmp=tmp/10;

        for(int i=0; i<tot; i++)
        {
            ans[cnt++]=u[i]+0;
            if((i+1)%3==0&&tot-i!=1) ans[cnt++]=,;
        }
        if(a<0) ans[cnt++]=-;
        for(int i=cnt-1; i>=0; i--) printf("%c",ans[i]);
        printf("\n");
    }
    return 0;
}

 

PAT (Advanced Level) 1001. A+B Format (20)

标签:

原文地址:http://www.cnblogs.com/zufezzt/p/5495934.html

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