hdu3787 A+B

Problem 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
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#define INF 1e9
const int maxn = 400+10;
using namespace std;
char BUFA[15], BUFB[15];
int main()
{
	int i, j, k;
	int a, b;
	while (scanf("%s%s", BUFA, BUFB) == 2)
	{
		i = strlen(BUFA);
		j = strlen(BUFB);
		a = b = 0;
		for (k = 0; k != i; ++k)
		{
			if (BUFA[k] == ',')continue;
			if (isdigit(BUFA[k]))
			{
				a = a * 10 + (BUFA[k] - '0');
				continue;
			}
		}
		if (BUFA[0] == '-') a = -a;
		for (k = 0; k != j; k++)
		{
			if (BUFB[k] == ',') continue;
			if (isdigit(BUFB[k]))
			{
				b = b * 10 + (BUFB[k] - '0');
				continue;
			}
		}
		if (BUFB[0] == '-') b = -b;
		printf("%d\n", a + b);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值