80分求助

P1303 A*B Problem

qingkongd_Rj @ 2023-03-07 20:17:22

#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <string>
using namespace std;
char a[1001] , b[1001];
int a1[1001], b1[1001], c[1001];
int main(){
    cin >> a >> b;
    int lena = strlen(a);
    int lenb = strlen(b);
    for (int i = 0; i < lena; i++){
        a1[lena - 1 - i] = a[i] - 48;
    }
    for (int i = 0; i < lenb; i++){
        b1[lenb - 1 - i] = b[i] - 48;
    }
    for (int i = 0; i < lenb; i++){
        int x = 0;
        for(int j = 0; j < lena; j++){
            c[i+j] += b1[i] * a1[j] + x;
            x = c[i + j] /10;
            c[i + j] %= 10;
        }
        c[i + lena] = x;
    }
    int index = 0;
    for(int i = lena + lenb - 1; i >= 0; i--){
        if(c[i] != 0){
            index = i;
            break;
        }
    }
    for(int i = index; i >= 0; i--){
        cout << c[i];
    }
    return 0;
}

by Seapeac @ 2023-03-07 20:45:33

将输入的字符串转为数组后,当成多个高*单来算。


by haijun_ @ 2023-03-12 19:14:59

python


a=int(input())
b=int(input())
print(a*b)你看多简单

by zengqhuai @ 2023-05-13 15:17:45

@haijun_print(int(input())*int(input()))一行就可以过


|