求助,到底是哪出了问题

P1303 A*B Problem

yaoyao0407 @ 2020-08-18 15:57:53

运行结果没对(用的666666*99999999)

抱着试试的心态上了洛谷,自己挑不出啥毛病,求助

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string> 
using namespace std;
string cmp(string a,string b){
    if(a.length()>b.length()){
        return a;
    }
    if(b.length()<a.length()){
        return b;
    }
    int i;
    for(i=1;i<=a.length();i++){
        if(a[i]>b[i]){
            return a;
        }
        if(b[i]>a[i]){
            return b;
        }
    }
    if(i==(a.length()+1)){
        return a;
    }
}
int main(){
    string a,b,c,e,min;
    cin>>a>>b;
    min=cmp(a,b);
    if(min==b){
        swap(a,b);
    }
    for(int i=1;i<=a.length();i++){
        c[0]=0;
        for(int j=1;j<=b.length();j++){
            e[i]=(a[i]*b[j])/10+c[j-1];
            c[j]=(a[i]*b[j])%10;
        }
    }
    for(int i=1;i<=e.length();i++){
        cout<<e[i];
    }
    return 0;
}

by yaoyao0407 @ 2020-08-18 15:59:29

两个WA,三个RE,救救孩子吧


by 听取MLE声一片 @ 2020-08-18 16:07:50

@yaoyao0407 显然,e和c应该是int


by konjacq @ 2020-08-18 16:10:26

@yaoyao0407 显然,您需要^48或者-48


by yaoyao0407 @ 2020-08-18 16:36:16

@听取MLE声一片 那数组开多大啊


by yaoyao0407 @ 2020-08-18 16:36:35

@konjacq 哪里


by yaoyao0407 @ 2020-08-18 16:36:55

@konjacq 为啥


by konjacq @ 2020-08-18 16:38:41

@yaoyao0407 您string里面存的是ASCII码,0的ASCII码是48,149...所以需要先全部-48


by yaoyao0407 @ 2020-08-18 16:41:39

@konjacq 例如a-=48?


by konjacq @ 2020-08-18 16:43:27

@yaoyao0407 读进来就先每个a_i\gets a_i-48


by yaoyao0407 @ 2020-08-18 16:47:06

@konjacq 没看懂……


| 下一页