20pts求助

P1303 A*B Problem

QAQ_liu @ 2024-10-25 12:23:30


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    string s1,s2,s3;
    cin>>s1>>s2;
    if(s1.size()<s2.size()){
        while(s1.size()<s2.size()) s1='0'+s1;
    }else if(s2.size()<s1.size()){
        while(s2.size()<s1.size()) s2='0'+s2;
    }
    int shengyu=0,jingwei=0;
    for(int i=s1.size()-1;i>=0;i--){
        int num=s1[i]-'0',num2=s2[i]-'0';
        int c=num*num2;
        int shengyu=c%10,jingwei=c/10;
        s3[i]=char(shengyu+'0');
        if(jingwei!=0){
            if(i-1>-1) s3[i-1]=char((int)(s3[i-1])*jingwei);
            else cout<<jingwei;
        }
    }
    for(int i=s3.size()-1;i>=0;i--) cout<<s3[i];
    return 0;
}

|