A+B

xiaoxiao2021-02-28  50

概要

题目描述 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号”,”隔开。 现在请计算A+B的结果,并以正常形式输出。 输入描述: 输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9)。 输出描述: 请计算A+B的结果,并以正常形式输出,每组数据占一行。 示例1 输入

-234,567,890 123,456,789 1,234 2,345,678 输出

-111111101 2346912


AC代码

#include <iostream> #include <cstring> using namespace std; string A,B; long long x,y; long long Tranform(string str) { long long tmp = 0; int flag = 1; if(str[0] == '-'){ flag = -1; str = str.substr(1,str.length()-1); } for(int i = 0 ; i < str.length() ; i++){ if(str[i] >= '0' && str[i] <= '9'){ tmp = tmp*10 + (str[i]-'0'); } } return tmp*flag; } int main() { while(cin>>A>>B){ x = Tranform(A); y = Tranform(B); cout<<x+y<<endl; } return 0; }
转载请注明原文地址: https://www.6miu.com/read-2630756.html

最新回复(0)