求助为什么全RE,本地用最大的数相加没问题
查看原帖
求助为什么全RE,本地用最大的数相加没问题
319478
zhibuba楼主2020/5/9 13:29
#include <stdio.h>
#include <string.h>

#define MAX(x,y) (((x)>(y))?(x):(y))
#define MIN(x,y) (((x)<(y))?(x):(y))

typedef char INT[502];

void plus(INT a, INT b, INT c)
{
	int len_a = strlen(a), len_b = strlen(b);
	int len_c = MAX(len_a, len_b);
	int len_m = MIN(len_a, len_b);
	c[len_c] = '\0';
	int i = 1, t = 0;
	while (i <= len_m)
	{
		int A = a[len_a - i] - '0', B = b[len_b - i] - '0';
		c[len_c - i] = (A + B + t) % 10 + '0';
		t = (A + B + t >= 10);
		i++;
	}
	if (len_a > len_b)
		while (i <= len_c)
		{
			int A = a[len_a - i] - '0';
			c[len_c - i] = (A + t) % 10 + '0';
			t = (A + t >= 10);
			i++;
		}
	if (len_a < len_b)
		while (i <= len_c)
		{
			int B = b[len_b - i] - '0';
			c[len_c - i] = (B + t) % 10 + '0';
			t = (B + t >= 10);
			i++;
		}
	if (t)
	{
		INT d;
		strcpy(d + 1, c);
		strcpy(c, d);
		c[0] = '1';	
	}
	return; 
}

int main(void)
{
	INT a, b, c;
	scanf("%s %s", a, b);
	plus(a, b, c);
	printf("%s", c);
	return 1;
}
2020/5/9 13:29
加载中...