标签:
题目描述:
给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开。
现在请计算A+B的结果,并以正常形式输出。
输入:
输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9)。
输出:
请计算A+B的结果,并以正常形式输出,每组数据占一行。
样例输入:
-234,567,890 123,456,7891,234 2,345,678
样例输出:
-1111111012346912
#include <iostream> #include <stdio.h> #include <cmath> #include <cstdlib> using namespace std; int main() { //-234,567,890 123,456,789 int num1,num2,num3; long number1,number2,sum; int weishu ; num1 = 1000; num2 = 1000; num3 = 1000; while(scanf("%d,%d,%d",&num1,&num2,&num3) != EOF) { weishu = 0; if(num3 <= 999) weishu++; if(num2 <= 999) weishu++; if(num1 <=999) weishu++; if(weishu == 3) number1 = abs(num1) * 1000000 + num2 * 1000 + num3; if(weishu == 2) number1 = abs(num1) * 1000 + num2; if(weishu == 1) number1 = abs(num1); if(num1 <0) number1 = number1 * -1; num1 = 1000; num2 = 1000; num3 = 1000; scanf("%d,%d,%d",&num1,&num2,&num3); weishu = 0; if(num3 <= 999) weishu++; if(num2 <= 999) weishu++; if(num1 <=999) weishu++; if(weishu == 3) number2 = abs(num1) * 1000000 + num2 * 1000 + num3; if(weishu == 2) number2 = abs(num1) * 1000 + num2; if(weishu == 1) number2 = abs(num1); if(num1 < 0) number2 = number2 * -1; sum = number1 + number2; cout << sum << endl; num1 = 1000; num2 = 1000; num3 = 1000; sum=0; } return 0; }
标签:
原文地址:http://blog.csdn.net/mycomein/article/details/46336069