P1601 A+B Problem(高精)WA40
  • 板块学术版
  • 楼主Zhang_enze
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/8/7 17:08
  • 上次更新2024/8/7 18:39:22
查看原帖
P1601 A+B Problem(高精)WA40
1415235
Zhang_enze楼主2024/8/7 17:08
#include <iostream>
#include <string>
using namespace std;
string a, b;
int c[100005], d[100005], ans[100005];
void Plus(string x, string y) {
	int lx = x.size(), ly = y.size();
	for (int i = 0; i < lx; i ++) {
		c[i] = a[lx-i-1] - 48;
	}
	for (int i = 0; i < ly; i ++) {
		d[i] = b[ly-i-1] - 48;
	}
	int tmp = 0;
	for (int i = 0; i < max(lx, ly); i ++) {
		ans[i] = (c[i] + d[i]) % 10 + tmp;
		tmp = (c[i] + d[i]) / 10;
	}
	if (tmp != 0) {
		cout << tmp;
	}
	for (int i = max(lx, ly) - 1; i >= 0; i --) {
		cout << ans[i];
	}
}
int main() {
	cin >> a >> b;
	Plus(a, b);
	return 0;
}

WA40分求调

2024/8/7 17:08
加载中...