A1001. A+B Format

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<cstdio>
 2 #include<iostream>
 3 #include<string.h>
 4 using namespace std;
 5 int main(){
 6     int a, b, c, sign = 0, bt;
 7     char prt[30];
 8     scanf("%d%d", &a, &b);
 9     c = a + b;
10     if(c < 0){
11         c = -1 * c;
12         sign =1;
13     }
14     int i = 0, tag = 0;
15     do{
16         bt = c % 10;
17         c = c / 10;
18         prt[i++] = '0' + bt;
19         tag++;
20         if(tag != 0 && tag % 3 == 0){
21             prt[i++] = ',';
22         }
23     }while(c != 0);
24     if(prt[i - 1] != ',')
25         prt[i] = '\0';
26     else
27         prt[i - 1] = '\0';
28     if(sign == 1)
29         printf("-");
30     for(int j = strlen(prt) - 1; j >= 0; j--)
31         printf("%c", prt[j]);
32     cin >> a;
33     return 0;
34 }
View Code

 

注意:在整个数字的最高位前不能有逗号。

posted @ 2018-01-20 15:34  ZHUQW  阅读(104)  评论(0编辑  收藏  举报