题目1003:A+B
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:14080
解决:5895
-
题目描述:
-
给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开。
现在请计算A+B的结果,并以正常形式输出。
-
输入:
-
输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9)。
-
输出:
-
请计算A+B的结果,并以正常形式输出,每组数据占一行。
-
样例输入:
-
-234,567,890 123,456,789 1,234 2,345,678
-
样例输出:
-
-111111101 2346912
-
来源:
//一开始以为会是大数问题,结果数据数据那么水,-10^9~~10^9
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char str1[20];
char str2[20];
int main()
{
while(scanf("%s %s",str1,str2)!=EOF)
{
int len1=strlen(str1);
int len2=strlen(str2);
int num1=0;
int num2=0;
for(int i=0;i<len1;i++)
{
if(str1[i]>='0'&&str1[i]<='9')
{
num1=num1*10+(str1[i]-'0');
}
}
for(int i=0;i<len2;i++)
{
if(str2[i]>='0'&&str2[i]<='9')
{
num2=num2*10+(str2[i]-'0');
}
}
if(str1[0]!='-'&&str2[0]!='-')//++
{
printf("%d\n",num1+num2);
}
else if(str1[0]!='-'&&str2[0]=='-')//+-
{
printf("%d",num1-num2);
}
else if(str1[0]=='-'&&str2[0]!='-')//-+
{
printf("%d\n",num2-num1);
}
else
{
printf("%d\n",0-(num1+num2));
}
}
return 0;
}