20分求调
  • 板块P1303 A*B Problem
  • 楼主lvmuyan
  • 当前回复3
  • 已保存回复3
  • 发布时间2025/7/19 14:31
  • 上次更新2025/7/19 17:37:59
查看原帖
20分求调
1673660
lvmuyan楼主2025/7/19 14:31
#include <bits/stdc++.h>
using namespace std;
char a[10005],b[10005];
int n[10005],m[10005],c[10005];
int main(){
	cin >> a >> b;
	int lena=strlen(a);
	int lenb=strlen(b);
	for(int i=1;i<=lena;i++){
		n[i]=a[lena-i]-'0';
	}
	for(int i=1;i<=lenb;i++){
		m[i]=b[lenb-i]-'0';
	}
	for(int i=1;i<=lenb;i++){
		for(int j=1;j<=lena;j++){
			c[i+j-1]=n[j]*m[i];
		}
	}
	int x=lena+lenb;
	for(int i=1;i<x;i++){
		if(c[i]>9){
			c[i+1]+=c[i]/10;
			c[i]%=10;
		}
	}
	x=lena+lenb;
	while(c[x] == 0 && x > 1){
		x--;
	}
	for(int i=x;i>0;i--){
		cout << c[i];
	}
	return 0;
}

只对了第一个测试用例,不知道哪里错了,有大佬可以帮忙调一调吗(可以关注)?

2025/7/19 14:31
加载中...