A+B

Description

给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开。
现在请计算A+B的结果,并以正常形式输出。

Input

输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9)。

Output

请计算A+B的结果,并以正常形式输出,每组数据占一行。

Sample Input

-234,567,890 123,456,789

1,234 2,345,678

Sample Output

-111111101

2346912

代码如下:

#include<iostream>

#include<string>

using namespace std;

int main()

{

   string a1,a2;

   while(cin>>a1>>a2){

       int l1=a1.size();

       int l2=a2.size();

       int x1,x2;

       x1=x2=0;

       int f=1;

       for(int i=0;i<l1;i++)

       {

               if(a1[i]=='-'){f=-1;continue;}

               if(a1[i]!=','){

                   x1=x1*10+a1[i]-'0';

                   }

       }

       x1=x1*f;

       f=1;

       for(int i=0;i<l2;i++){

               if(a2[i]=='-'){f=-1;continue;}

               if(a2[i]!=','){

                   x2=x2*10+a2[i]-'0';

                   }

                   }

               x2=x2*f;

       cout<<x1+x2<<endl;

       }

   //system("pause");

   return 0;

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章