A1001. A+B Format (20)

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

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.

Sample Input

-1000000 9

Sample Output

-999,991
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <algorithm>
 4 #include <string.h>
 5 using namespace std;
 6 
 7 const int maxn =100010;
 8 int a,b,sum;
 9 
10 
11 int main(int argc, char* argv[])
12 {
13     scanf("%d%d",&a,&b);
14     sum=a+b;
15     int num[10];
16     if(sum<0)
17     { 
18     printf("-");
19     sum=-1*sum; 
20     }
21     int len=0;
22     if(sum==0)num[len++]=0;
23     while(sum)
24     {
25     num[len++]=sum%10;
26     sum/=10;
27     }
28     for(int k=len-1;k>=0;k--)
29 {
30 printf("%d",num[k]);
31 if(k>0&&k%3==0)printf(",");
32 }
33     system("pause"); 
34     return 0;
35 }

 

posted @ 2015-03-14 07:03  Joilee  阅读(303)  评论(0编辑  收藏  举报