1817: A+B

389 篇文章 1 订阅

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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值