题目描述
给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开。
现在请计算A+B的结果,并以正常形式输出。
输入
输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9)。
输出
请计算A+B的结果,并以正常形式输出,每组数据占一行。
样例输入 Copy
-234,567,890 123,456,789
1,234 2,345,678
样例输出 Copy
-111111101
2346912
#include<stdio.h>
#include<math.h>
int main(){
int a;
char b;
int s,i,j;
int sum,sum1,sum2;
int first = 1;
int bb[100];
int k = 0;//record how many "," that the number has
for (i=0;i<10000;i++)
{
s = scanf("%d%c",&a,&b);
if (s==-1) //not at the end
break;
else //read in the number successfully
{
if (first==1)
{
if (b==',') //the first number
bb[k++] = a;
else if (b==' ')//the second number begins
{
sum1 = 0;
first = 0;
bb[k++] = a;
for (j=0;j<k;j++)
sum1+=pow(10,(k-j-1)*3)*abs(bb[j]);
if (bb[0]<0)
sum1*=(-1);
k = 0;
}
}
else
{
if (b==',') //the first number
bb[k++] = a;
else if (b=='\n')//the second number begins
{
sum2 = 0;
first = 1;//the first number begins
bb[k++] = a;
for (j=0;j<k;j++)
sum2+=pow(10,(k-j-1)*3)*abs(bb[j]);
if (bb[0]<0)
sum2*=(-1);
printf("%d\n",sum2+sum1);
k = 0;
}
}
}
}
return 0;
}