测试点数据本地过,洛谷不过?!!4wa!!
查看原帖
测试点数据本地过,洛谷不过?!!4wa!!
921176
leiwenjin1234楼主2023/10/1 18:37
#include<bits/stdc++.h>
using namespace std;
stack<int> num2;
stack<int> num;
stack<int> ans;
char x;
int main() {
	while (1) {
		x = getchar();
		if (x > '9' || x < '0')break;			
		int a = x - '0';
		num.push(a);
	}
	while (1) {
		x = getchar();
		if (x > '9' || x < '0')break;			
		int a = x - '0';
		num2.push(a);
	}
	bool j = false;
	while (!num.empty() && !num2.empty()) {
		int f = num.top() + num2.top();
		num.pop();
		num2.pop();
		if (j)f++, j = 0;
		if (f > 9) {
			f -= 10;
			j = 1;
		}
		ans.push(f);
	}
	while (!num.empty()) {
		int f = num.top();
		if (j) {
			f++;
			j = 0;
		}
		if (f > 9) {
			f -= 10;
			j = 1;
		}
		ans.push(f);
		num.pop();

	}
	while (!num2.empty()) {
		int f = num2.top();
		if (j) {
			f++;
			j = 0;
		}
		if (f > 9) {
			f -= 10;
			j = 1;
		}
		ans.push(f);
		num2.pop();

	}
	if (j)cout << "1";
	while (!ans.empty()) {
		cout << ans.top();
		ans.pop();
	}

}

心血来潮写的高精度。
测试点2: 123 123
程序结果:246
我:???

2023/10/1 18:37
加载中...