0pts求调(自己测试能过,但提交后不对)
查看原帖
0pts求调(自己测试能过,但提交后不对)
1633681
BBDD114514楼主2025/7/29 19:18
#include <stdio.h>
#define MAX 2000

int main(){
	int a[MAX], b[MAX]; // 用于储存两个数 
	int la=0, lb=0; // 储存两个数的长度 
	while (1){ // 输入a 
		char c;
		scanf("%c", &c);
		if (c == '\n') break;
		a[la++] = (int)c - 48;
	}
	while (1){ // 输入b 
		char c;
		scanf("%c", &c);
		if (c == '\n') break;
		b[lb++] = (int)c - 48;
	}
	int res[2*MAX]; // 用于储存结果 
	for (int i=0;i<2*MAX;i++){ // 初始化 
		res[i]=0;
	}
	for (int i=la-1;i>=0;i--){ // 自右向左读取两个数的每一位 
		for (int j=lb-1;j>=0;j--){
			int mul = a[i]*b[j]; // 计算这两个数的当前位的积 
			int index = 2*MAX-la-lb+i+j+1; // 计算储存结果的索引(从右往左储存) 
			res[index] += mul; // 将结果加到该索引中 
			while (res[index] > 9){ // 进位 
				res[index-1] += res[index]/10;
				res[index] %= 10;
				index--;
			}
		}
	}
	bool ignore0 = true; // 用于判断是否忽略前置0 
	for (int i=0;i<2*MAX;i++){
		if (ignore0 && res[i] == 0) continue; // 忽略前置0 
		ignore0 = false; // 如果开始出现不是零的数,结束忽略0 
		printf("%d", res[i]); // 输出该位 
	}
	return 0; // end 
}

2025/7/29 19:18
加载中...