1001 A+B Format
1001 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 Specification:
Each input file contains one test case. Each case contains a pair of integers a and b where −106≤a,b≤106. The numbers are separated by a space.
Output Specification:
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 <map> 2 #include <set> 3 #include <queue> 4 #include <cmath> 5 #include <stack> 6 #include <vector> 7 #include <string> 8 #include <cstdio> 9 #include <cstring> 10 #include <climits> 11 #include <iostream> 12 #include <algorithm> 13 #define wzf ((1 + sqrt(5.0)) / 2.0) 14 #define INF 0x3f3f3f3f 15 #define LL long long 16 using namespace std; 17 18 int a, b, sum, cnt; 19 20 stack <char> s; 21 22 int main() 23 { 24 scanf("%d%d", &a, &b); 25 sum = a + b, cnt = 0; 26 if (sum < 0) 27 { 28 printf("-"); 29 sum = abs(sum); 30 while (sum) 31 { 32 cnt ++; 33 s.push('0' + sum % 10); 34 sum /= 10; 35 if (sum != 0 && cnt % 3 == 0) 36 s.push(','); 37 } 38 while (s.size()) 39 { 40 printf("%c", s.top()); 41 s.pop(); 42 } 43 printf("\n"); 44 } 45 else if (sum > 0) 46 { 47 while (sum) 48 { 49 cnt ++; 50 s.push('0' + sum % 10); 51 sum /= 10; 52 if (sum != 0 && cnt % 3 == 0) 53 s.push(','); 54 } 55 while (s.size()) 56 { 57 printf("%c", s.top()); 58 s.pop(); 59 } 60 printf("\n"); 61 } 62 else 63 printf("0\n"); 64 return 0; 65 }