首页 > 其他 > 详细

1001. A+B Format

时间:2015-01-26 22:52:52      阅读:303      评论:0      收藏:0      [点我收藏+]

Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).

Input

Each input file contains one test case. Each case contains a pair of integers a and b where -1000000 <= a, b <= 1000000. The numbers are separated by a space.

Output

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Draw (char *str,int a,int b);
int main ()
{
    long a,b;
    scanf("%ld %ld",&a,&b);
    long c=a+b;
    char str[9];
    sprintf(str,"%d",c);
    int length=strlen(str);
    if( str[0]-'-'==0)
    {
        printf("-");
        Draw(str,1,length-1);
        }
    else Draw(str,0,length-1);
    printf("\n");
    system("pause");
    return 0;
    }
void Draw (char *str,int a,int b)
{
     int length=b-a+1;
     int c=length%3,i;
     for (i=0;i<c;i++) printf("%c",str[i+a]);
     while( i<length) 
     {
            if( i!=0) printf(",");
            printf("%c",str[i+a]);
            i++;
            printf("%c",str[i+a]);
            i++;
            printf("%c",str[i+a]);
            i
            ++;
            }
     }

For each test case, you should output the sum of a and b in one line. The sum must be written in the standard format.

1001. A+B Format

原文:http://blog.csdn.net/lchinam/article/details/43157783

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!