你好,1WA,5RE

P1303 A*B Problem

XSean @ 2022-08-13 22:41:08


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int a[1001]={},b[1001]={},c[1001];
int main(){
/*
freopen (".in","r",stdin);
freopen (".out","w",stdout);
*/
cin>>s1>>s2;
int len1=s1.length(),len2=s2.length();
for(int i=len1-1,j=1;i>=0,j<=len1;i--,j++){
    a[j]=s1[i]-48;
}
for(int i=len2-1,j=1;i>=0,j<=len2;i--,j++){
    b[j]=s2[i]-48;
}
for(int i=1;i<=len2;i++){
    for(int j=1;j<=len1;j++){
        c[i+j-1]+=a[j]*b[i];
        c[i+j]+=c[i+j-1]/10;
        c[i+j-1]%=10;
    }
}
int maxl=len1+len2;
for(int i=maxl;i>=1;i--){
    if(c[i]==0){
        maxl--;
    }else{
        break;
    }
}
for(int i=maxl;i>=1;i--){
    cout<<c[i];
}

/*
fclose(stdin);
fclose(stdout);
*/
    return 0;
}

by XSean @ 2022-08-13 23:19:27

@sb_yyds 谢谢


上一页 |