1817: A+B
时间限制: 1 Sec 内存限制: 32 MB
献花: 200 解决: 145
[献花][花圈][TK题库]
题目描述
给定两个整数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
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
const int maxSize = 128;
int main()
{
#ifdef _DEBUG
ifstream cin("data.txt");
#endif // _DEBUG
bool negflag = false;
char array[maxSize] = {'\0'};
while(cin.getline(array, maxSize))
{
int A = 0, B = 0;
int index = 0;
if (array[index] == '-') { negflag = true; ++index; }
for (; array[index] != ' '; ++index)
{
if (array[index] == ',') { continue; }
A *= 10;
A += (array[index] - '0');
}
if (negflag) { A = -A; negflag = false; }
if (array[++index] == '-') { negflag = true; ++index; }
for (; array[index] != '\0'; ++index)
{
if (array[index] == ',') { continue; }
B *= 10;
B += (array[index] - '0');
}
if (negflag) { B = -B; negflag = false; }
cout << A + B << endl;
}
#ifdef _DEBUG
cin.close();
system("pause");
#endif // _DEBUG
return 0;
}