80 分求助,第一点WA

P1303 A*B Problem

optimize00 @ 2023-08-21 16:26:15

#include <bits/stdc++.h>
using namespace std;
string a,b;
int l;
int c[10010],d[10010],e[10020];
void my(){
    l=a.length()+b.length()-1; 
    for(int i=1;i<=a.length();i++){
        for(int j=1;j<=b.length();j++){
            e[i+j-1]+=c[i]*d[j];
            e[i+j]+=e[i+j-1]/10;
            e[i+j-1]=e[i+j-1]%10;
            if(i==a.length()&&j==b.length()&&e[l+1]!=0){
                l++;
            }
        }
    }
}
int main(){
    cin>>a>>b;
    for(int i=1;i<=a.length();i++){
        c[i]=a[a.length()-i]-'0';
    }
    for(int i=1;i<=b.length();i++){
        d[i]=b[b.length()-i]-'0';
    }
    my();
    for(int i=l;i>0;i--)cout<<e[i];
    return 0;
}

by JerryLee123 @ 2023-08-21 16:33:16

给一组数据

3312

0

你的答案:0000

正确答案:0


by optimize00 @ 2023-08-21 19:21:18

@JerryLee123 666


by mayixiao123 @ 2023-08-25 17:51:03

直接输出一个a*b的结果不就成了吗


by mayixiao123 @ 2023-08-25 17:52:19

long long a,b; cin >> a >> b; cout << a*b;


by mayixiao123 @ 2023-08-25 17:53:25

我一个绿名都看不懂你的代码QAQ


by renchengxin @ 2023-08-27 16:11:51

@linqiteng 没有考虑两数为零的情况


by renchengxin @ 2023-08-27 16:12:44

@linqiteng 第一个测试点为 0 10


by optimize00 @ 2023-08-30 11:10:17

@mayixiao123 高精度,解决long long没办法的问题


by xdcm @ 2023-08-30 23:16:32

@mayixiao123 请仔细查看数据范围


by Breeze_Clouds @ 2023-09-16 19:33:22


|