本地都过了的样例在洛谷过不了,只ac了一个救命
查看原帖
本地都过了的样例在洛谷过不了,只ac了一个救命
1283182
_pluviophile_123楼主2024/3/25 12:21
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
string a;
string b;

int main()
{
	cin >> a >> b;
	int jinwei = 0;
	int i = a.size() - 1;
	int j = b.size() - 1;
	char* res = (char*)malloc(sizeof(char)*(i+j+3));
	int k = i + j+1;
	res[k + 1] = '\0';
	while (i >= 0 || j >= 0)
	{
		int t1 = i >= 0 ? a[i] - '0' : 0;
		int t2 = j >= 0 ? b[j] - '0' : 0;
		res[k--] = (t1 + t2 + jinwei) % 10+'0';
		jinwei = (t1 + t2 + jinwei) / 10;
		i--, j--;
	}
	res[k] = jinwei+'0';
	for (i = (jinwei>0?k:k+1); i < strlen(res); i++) cout << res[i];
}
2024/3/25 12:21
加载中...