user-0 提问: 大整数加法测试了没发现哪里错了但是提交到网上总是提示结果错误

回复:
user: user-0
content: 引用 6 楼 wusuopuBUPT 的回复:#include <stdio.h> #include <stdlib.h> #include <string.h>  int main() { 	int a[200] = { 0 }, b[200] = { 0 }, sum[202] = { 0 }; 	char x[200], y[200]; 	fgets(x, sizeof(x), stdin); 	fgets(y, sizeof(y), stdin);  	int i = 0; 	int j = strlen(x); 	int k = strlen(y); 	for (i = 0; i < j; i++) //把字符数组转换成整形数组 		a[i] = x[i] - 48; 	for (i = 0; i < k; i++) 		b[i] = y[i] - 48; 	int n; 	if (j > k) 		n = j; 	else 		n = k; 	i = 1; 	while (n--) { 		int h = 0; 		int j1 = a[j - i], j2 = b[k - i]; 		if (j - i < 0) //如果两个数字位数不同j-i越界后将第一个加数置0 			j1 = 0; 		if (k - i < 0) 			j2 = 0; 		h = j1 + j2; 		sum[202 - i] += h; 		if (sum[202 - i] / 10 == 1) //进位 				{ 			sum[202 - i - 1]++; 			sum[202 - i] = sum[202 - i] % 10; 		} 		i++; 	} 	i = 0; 	while (sum[i] == 0) //抹0 	{ 		i++; 	} 	for (; i < 201; i++) //输出结果 		printf("%d", sum[i]); 	printf("\n"); 	return 0; }  还是不行啊，应该不是gets那里的错

user: user-1
content: #include <stdio.h> #include <stdlib.h> #include <string.h>  int main() { 	int a[200] = { 0 }, b[200] = { 0 }, sum[202] = { 0 }; 	char x[200], y[200]; 	fgets(x, sizeof(x), stdin); 	fgets(y, sizeof(y), stdin);  	int i = 0; 	int j = strlen(x); 	int k = strlen(y); 	for (i = 0; i < j; i++) //把字符数组转换成整形数组 		a[i] = x[i] - 48; 	for (i = 0; i < k; i++) 		b[i] = y[i] - 48; 	int n; 	if (j > k) 		n = j; 	else 		n = k; 	i = 1; 	while (n--) { 		int h = 0; 		int j1 = a[j - i], j2 = b[k - i]; 		if (j - i < 0) //如果两个数字位数不同j-i越界后将第一个加数置0 			j1 = 0; 		if (k - i < 0) 			j2 = 0; 		h = j1 + j2; 		sum[202 - i] += h; 		if (sum[202 - i] / 10 == 1) //进位 				{ 			sum[202 - i - 1]++; 			sum[202 - i] = sum[202 - i] % 10; 		} 		i++; 	} 	i = 0; 	while (sum[i] == 0) //抹0 	{ 		i++; 	} 	for (; i < 201; i++) //输出结果 		printf("%d", sum[i]); 	printf("\n"); 	return 0; }

user: user-2
content: 引用 3 楼 xlz35429674 的回复:[quote=引用 2 楼 derekrose 的回复:] 这种东西没必要非要accept 很浪费生命 这是一个比赛的评分标准啊[/quote]  如果是比赛 上面的话当我没说 哈哈

user: user-0
content: 引用 1 楼 wusuopuBUPT 的回复:gets_s()不是C99的标准，OJ平台的GCC不认识你的gets_s()函数.换成fgets()。  参考：https://forums.freebsd.org/viewtopic.php?&t=10428 http://stackoverflow.com/questions/15149168/undefined-reference-to-gets-s 改了也不行啊

user: user-0
content: 引用 2 楼 derekrose 的回复:这种东西没必要非要accept 很浪费生命 这是一个比赛的评分标准啊

user: user-2
content: 这种东西没必要非要accept 很浪费生命

user: user-1
content: gets_s()不是C99的标准，OJ平台的GCC不认识你的gets_s()函数.换成fgets()。  参考：https://forums.freebsd.org/viewtopic.php?&t=10428 http://stackoverflow.com/questions/15149168/undefined-reference-to-gets-s

user: user-3
content: 仅供参考#include <stdio.h> #include <string.h> #define MAXLEN 1000 char a1[MAXLEN]; char a2[MAXLEN]; static int v1[MAXLEN]; static int v2[MAXLEN]; static int v3[MAXLEN]; int i,j,n,L,z; void main(void) {     scanf("%d",&n);     for (j=0;j<n;j++) {         scanf("%s%s",a1,a2);          L=strlen(a1);         for (i=0;i<L;i++) v1[i]=a1[L-1-i]-'0';          L=strlen(a2);         for (i=0;i<L;i++) v2[i]=a2[L-1-i]-'0';          for (i=0;i<MAXLEN;i++) v3[i]=v1[i]+v2[i];          for (i=0;i<MAXLEN;i++) {             if (v3[i]>=10) {                 v3[i+1]+=v3[i]/10;                 v3[i]=v3[i]%10;             }         }          printf("Case %d:\n", j+1);         printf("%s + %s = ", a1, a2);          z=0;         for (i=MAXLEN-1;i>=0;i--) {             if (z==0) {                 if (v3[i]!=0) {                     printf("%d",v3[i]);                     z=1;                 }             } else {                 printf("%d",v3[i]);             }         }         if (z==0) printf("0");          printf("\n");     } } //Sample Input //3 //0 0 //1 2 //112233445566778899 998877665544332211 // //Sample Output //Case 1: //0 + 0 = 0 //Case 2: //1 + 2 = 3 //Case 3: //112233445566778899 + 998877665544332211 = 1111111111111111110

user: user-1
content: 我重新写了一个，楼主，仅供参考：  #include <stdio.h> #include <stdlib.h> #include <string.h>  int main() { 	int a[200] = {0}, b[200] = {0}, sum[202] = {0}; 	char x[200], y[200]; 	fgets(x, sizeof(x), stdin); 	fgets(y, sizeof(y), stdin);  	int len_i = strlen(x) - 1; //注意字符串结尾的'\0'不能算进来 	int len_j = strlen(y) - 1;  	int i, j; 	for(i = 0; i < len_i; i++) { 		a[len_i-1-i] = x[i] - 48; //reverse 	} 	for(j = 0; j < len_j; j++) { 		b[len_j-1-j] = y[j] - 48; 	}  	int n; 	n = len_i >= len_j ? len_i : len_j;  	i = 0; 	int temp_c = 0; 	for(; i < n; i++) { 		int temp_s = a[i] + b[i] + temp_c; 		sum[i] = temp_s % 10; 		temp_c = temp_s / 10; 		//printf("a=%d,b=%d,sum[i]=%d,temp_c=%d\n", a[i], b[i],sum[i],temp_c); 	} 	if(temp_c != 0) { 		sum[n] = temp_c; 		n++; 	} 	for (i = n-1; i >= 0; i--) { 		printf("%d", sum[i]); 	} 	putchar('\n');  	return 0; }