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).
Each input file contains one test case. Each case contains a pair of integers a and b where ?. The numbers are separated by a space.
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.
-1000000 9
-999,991
#include<bits/stdc++.h> using namespace std; const int maxn=10010; int main(){ int a,b; scanf("%d %d",&a,&b); int c=a+b; if(c<0){ printf("-"); c=-c; } int num[maxn]; int i=0; if(c==0){ printf("%d\n",0); return 0; } while(c>0){ num[i]=c%1000; c/=1000; i++; } printf("%d",num[i-1]); for(int j=i-2;j>=0;j--){ printf(",%03d",num[j]); } printf("\n"); return 0; }
原文:https://www.cnblogs.com/dreamzj/p/14897656.html