1817:A+B

计算两个特定格式整数A+B的结果
博客围绕问题B,即计算两个整数A和B的和展开。A和B从个位开始每三位数用逗号隔开,输入包含多组数据,每组由两个整数A和B组成,需计算A+B结果并以正常形式输出,每组结果占一行。

问题 B: A+B

时间限制: 1 Sec  内存限制: 32 MB
提交: 760  解决: 426
[提交][状态][讨论版][命题人:外部导入]

题目描述

给定两个整数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>
using namespace std;
int main() {
	string str1, str2;
	while (cin >> str1 >> str2) {
		int x = 0, y = 0, flag = 1;
		for (int i = 0; i < str1.length(); i++) {
			if (str1[i] == ',')
				continue;
			if (str1[i] == '-') {
				flag = -1;
				continue;
			}
			x *= 10;
			x += str1[i] - '0';
		}
		x *= flag;
		flag = 1;
		for (int i = 0; i < str2.length(); i++) {
			if (str2[i] == ',')
				continue;
			if (str2[i] == '-') {
				flag = -1;
				continue;
			}
			y *= 10;
			y += str2[i] - '0';
		}
		y *= flag;
		cout << x + y << endl;
	}
}

 

<--- Last few GCs ---> [38972:0000016B889DF0D0] 403890 ms: Mark-sweep 1819.2 (2095.9) -> 1806.3 (2085.9) MB, 569.9 / 0.0 ms (average mu = 0.267, current mu = 0.248) allocation failure; GC in old space requested [38972:0000016B889DF0D0] 404624 ms: Mark-sweep 1817.7 (2095.8) -> 1806.6 (2084.8) MB, 662.4 / 0.0 ms (average mu = 0.193, current mu = 0.099) allocation failure; GC in old space requested <--- JS stacktrace ---> FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 1: 00007FF749E75AFF node_api_throw_syntax_error+174175 2: 00007FF749DF8F26 v8::internal::wasm::WasmCode::safepoint_table_offset+59926 3: 00007FF749DFABC0 v8::internal::wasm::WasmCode::safepoint_table_offset+67248 4: 00007FF74A8A6224 v8::Isolate::ReportExternalAllocationLimitReached+116 5: 00007FF74A8915B2 v8::Isolate::Exit+674 6: 00007FF74A71327C v8::internal::EmbedderStackStateScope::ExplicitScopeForTesting+124 7: 00007FF74A72055D v8::internal::Heap::PublishPendingAllocations+1117 8: 00007FF74A71D5E7 v8::internal::Heap::PageFlagsAreConsistent+3367 9: 00007FF74A70FD17 v8::internal::Heap::CollectGarbage+2039 10: 00007FF74A7266D3 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath+2099 11: 00007FF74A726F7D v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath+93 12: 00007FF74A72F8AF v8::internal::Factory::AllocateRaw+783 13: 00007FF74A742C7D v8::internal::FactoryBase<v8::internal::Factory>::NewHeapNumber<0>+685 14: 00007FF74A747128 v8::internal::FactoryBase<v8::internal::Factory>::NewRawTwoByteString+72 15: 00007FF74A4EE574 v8::internal::String::SlowFlatten+724 16: 00007FF74A8AFDAD v8::String::Utf8Length+141 17: 00007FF749E1F32E v8::internal::Malloced::operator delete+18078 18: 00007FF74A85EDDD v8::internal::Builtins::code+248285 19: 00007FF74A85E9E9 v8::internal::Builtins::code+247273 20: 00007FF74A85ECAC v8::internal::Builtins::code+247980 21: 00007FF74A85EB10 v8::internal::Builtins::code+247568 22: 00007FF74
最新发布
08-20
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值