40分求助!!!(在P1601A+B Problem(高精)也发了)

P1303 A*B Problem

dongrq_cs @ 2023-04-01 19:05:16

#include <bits/stdc++.h>
using namespace std;
void StrToInt(char s[],int t[]){
    int len = 0;
    for(len = 0;s[len] != '\0';len++){
        ;
    }
    t[0] = len;
    int j = len - 1;
    for(int i = 1;i <= len;i++,j--){
        t[i] = s[j] - '0';
    }
}
void add(int a[],int b[],int c[]){
    for(int i = 1;i <= b[0];i++){   
        int x = 0;
        for(int j = 1;j <= a[0];j++){
            c[i + j - 1] = b[i] * a[j] + x + c[i + j - 1];
            x = c[i + j - 1] / 10;
            c[i + j - 1] %= 10;
        }
        c[a[0] + i] += x;
    }
    int k = a[0] + b[0];
    while(c[k] == 0){
        k--;
    }
    c[0] = k;
}
int main(){
    char d[210],r[210];
    int a[210] = {0},b[210] = {0},c[210] = {0};
    cin >> d >> r;
    StrToInt(d,a);
    StrToInt(r,b);
    add(a,b,c);
    for(int i = c[0];i >= 1;i--){
        cout << c[i];
    }
    return 0;
}

by dongrq_cs @ 2023-04-01 19:27:08

@GJY201112 ???


by ShenEric @ 2023-04-01 19:27:25

@dongrq_cs


by dongrq_cs @ 2023-04-01 19:31:28

@ShenEric Tankyou


by ShenEric @ 2023-04-01 19:41:20

@dongrq_cs you are welcome


by zzhlzy200912 @ 2023-05-13 15:40:04

@dongrq_cs 用python一行就能搞定 print(int(input())*int(input()))


上一页 |