帮忙看一下呗

P1303 A*B Problem

2110215942l @ 2022-09-11 11:39:28

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    char a[60000],b[60000],c[60000];
    cin>>a>>b;
    int s1=strlen(a),s2=strlen(b);
    int x[50000],y[50000];
    for(int i=1;i<=s1;++i){
        x[i]=a[s1-i]-'0';
    }
    for(int j=1;j<=s2;++j){
        y[j]=b[s2-j]-'0';
    }
    int sum=s1+s2;
    for(int i=1;i<=s1;++i){
        for(int j=1;j<=s2;++j){
            c[i+j-1]+=x[i]*y[j];
        }
    }
    for(int i=1;i<=sum-1;++i){
        if(c[i]>9){
            c[i+1]+=c[i]/10;
            c[i]=c[i]%10;
        }
    }
    while(c[sum]==0&&sum>1) sum--;
    for(int i=sum;i>=1;--i){
        printf("%d",c[i]);
    }
    return 0;
 } 

by ALexanse @ 2022-09-15 21:26:22

@2110215942l 哥们,你把你的C数组改成int型就结了


by 2110215942l @ 2022-09-17 09:33:20

@ALexanse 哦哦,好像是,谢谢你!


|