SDNU 1113.A+B(水题)

mac2022-06-30  26

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

Source

浙大计算机研究生复试上机考试-2010年 #include<bits/stdc++.h> using namespace std; #define ll long long char a[1000+8], b[1000+8]; ll n, m, sum; int main() { while(~scanf("%s %s", a, b))//这里不加~的话,就会T { sum = 0; ll sign1 = 1, sign2 = 1, s1 = 0, s2 = 0; int len1 = strlen(a), len2 = strlen(b); for(int i = len1-1; i >= 0; i--) { if(a[i] != ',' && a[i] != '-') { // cout<<(int)a[i]-48<<" 0△0"<<endl; s1 += ((int)a[i]-48)*sign1; sign1 *= 10; } if(a[i] == '-')s1 = 0-s1; } // cout<<s1<<endl; for(int i = len2-1; i >= 0; i--) { if(b[i] != ',') { s2 += ((int)b[i]-48)*sign2; sign2 *= 10; } if(b[i] == '-')s2 = 0-s2; } sum = s1+s2; printf("%lld\n", sum); } return 0; }

 

转载于:https://www.cnblogs.com/RootVount/p/10970231.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)