求助!!为啥不能AC

P1303 A*B Problem

Evolution333 @ 2023-10-31 20:21:08

#include <iostream>
#include <vector>
#include <string>
using namespace std;

vector<int> mul(vector<int> &A,int b){
    vector<int> C;
    int t = 0;
    for(int i=0;i<A.size()||t;i++){
        if(i<A.size()) t += A[i]*b;
        C.push_back(t%10);
        t /= 10;
    }
    while(C.size()>1&&C.back()==0) C.pop_back();
    return C;

}

int main(){
    string a;
    vector<int> A;
    int b;
    cin>>a>>b;

    for(int i=a.size()-1;i>=0;i--) A.push_back(a[i]-'0');

    auto C = mul(A,b);

    for(int i=C.size()-1;i>=0;i--) cout<<C[i];

    return 0;

}

by __Cby___ @ 2023-10-31 20:26:53

你这是高精乘低精


by kkk02 @ 2023-11-01 21:46:13

#include<bits/stdc++.h>
using namespace std;
const int maxn=10000;
int main(){
    char numa[maxn],numb[maxn];
    int a[maxn],b[maxn],c[maxn];
    scanf("%s",numa);
    scanf("%s",numb);
    int la=strlen(numa);
    int lb=strlen(numb);
    memset(c,0,sizeof(c));
    for(int i=0;i<la;i++) a[la-i]=numa[i]-'0';
    for(int i=0;i<lb;i++) b[lb-i]=numb[i]-'0';
    for(int i=1;i<=la;i++){
        for(int j=1;j<=lb;j++)c[i+j-1]+=a[i]*b[j];
    }
    int lc=la+lb;
    for(int i=1;i<=lc;i++){
        c[i+1]+=c[i]/10;
        c[i]%=10;
    }
    while(c[lc]==0&&lc>1)lc--;
    for(int i=lc;i>=1;i--)cout<<c[i];
    return 0;
}

我程序阅读能力太差。 ac代码参考,自己看。


|