1001. A+b Format (+)Time limit MS
Memory Limit 65536 KB
Code length limit 16000 B
Program Standard author CHEN, Yue
Calculate A + B and output the sum in standard format – that's, the digits must be separated to groups of three by COM Mas (unless there is less than four digits).
Input
Each input file contains the one test case. Each case contains a pair of integers a and b where-1000000 <= A, b <= 1000000. The numbers is separated by a space.
Output
For each test case, you should output the sum of A and B on one line. The sum must is written in the standard format. Sample Input
-1000000 9
Sample Output
-999,991
Calculates the value of the a+b, separating each 3 digits of the result with a comma.
#include <bits/stdc++.h> using namespace std;
#define MAXN 1000010 #define INF 0xfffffff int main () {#ifdef Online_judge #else freopen ("F:/cb/read.txt", "R", stdin);
Freopen ("F:/cb/out.txt", "w", stdout);
#endif Ios::sync_with_stdio (FALSE);
Cin.tie (0);
int a,b,ans,i,j,cnt=0;
BOOL flag=true;//positive and negative sign cin>>a>>b;
Ans=a+b;
cout<< "ans=" <<ans<<endl;
if (ans<0) flag=false,ans=abs (ans);
Char S[MAXN],C[MAXN];
while (ans>0)//int to string {S[cnt++]=char (ans%10+ ' 0 ');
ans/=10;
} if (ans==0) c[0]= ' 0 ';
cnt=0;
For (I=strlen (s)-1; i>=0;-I.) c[cnt++]=s[i];
cout<< "c=" <<c<<endl;
int Len=strlen (c);
int TEMP=LEN/3;
if (len%3==0)--temp;//comma number//cout<< "len=" <<len<<endl;
cnt=0;
if (!flag) cout<< "-";
for (i=0; i<len-3*temp; ++i) cout<<c[i];
if (temp>0) {cout<< ",";for (j=i; j<len; ++j) {if (cnt==3) {cnt=0;
cout<< ",";
} cout<<c[j];
++cnt;
}} cout<<endl;
return 0;
}