A+B
点击打开链接
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3674 Accepted Submission(s): 2098
Problem Description
给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开。
现在请计算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
Source
思路:
直接计算 暴力 注意取值范围就行
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long int LL;
char s1[15];
char s2[15];
LL fun(char *s)
{
LL sum=0;
int len=strlen(s);
for(int i=0;i<len;i++)
if(s[i]>='0'&&s[i]<='9')
sum=sum*10+s[i]-'0';
return sum;
}
int main()
{
while(~scanf("%s %s",s1,s2))
{
LL x=fun(s1);
LL y=fun(s2);
if(s1[0]=='-')
x=-x;
if(s2[0]=='-')
y=-y;
printf("%lld\n",x+y);
}
return 0;
}