提交记录 18048


用户 题目 状态 得分 用时 内存 语言 代码长度
JOJO 1004a. 【模板题】高精度乘法2 Accepted 100 55.511 ms 332 KB C++ 2.05 KB
提交时间 评测时间
2022-09-19 21:12:07 2022-09-19 21:12:09
#include <iostream>
using namespace std;

const int scale = 10;

int main() {
    int n=1;
    // cin >> n;
    string aa, bb;
    int a[10001], b[10001], c[21000], nc[21000];
    for (int i = 0; i < n; i++) {
        cin >> aa >> bb;
        if (aa=="0" || bb=="0") {
            cout << 0;
            return 0;
        }
        int sizea = aa.length();
        int sizeb = bb.length();
        for (int i = 0; i < sizea; i++) {
            a[i] = aa[sizea - i - 1] - '0';

        }
        for (int i = 0; i < sizeb; i++) {
            b[i] = bb[sizeb - i - 1] - '0';

        }
        int sizec = sizea + sizeb - 1;

        int mark,small,large;
        if (sizea >= sizeb) {
            mark = 0;
            small = sizeb;
            large = sizea;
        }
        else {
            mark = 1;
            small = sizea;
            large = sizeb;
        }
            
        for (int p = 0; p < small; p++) {
            int sum = 0;
            for (int i = 0; i < p + 1; i++) {    
                sum += a[i] * b[p - i];        
            }  
            c[p] = sum;
        }
        for (int p = small; p < large; p++) {
            int sum = 0;
            if (mark) {
                for (int i = small - 1; i >= 0; i--) {
                    sum += a[i] * b[p - i];
                }
            }
            else {
                for (int i = small - 1; i >= 0; i--) {
                    sum += b[i] * a[p - i];
                }
            }
            c[p] = sum;
        }
        for (int p = large; p < sizec; p++) {
            int sum = 0;
            for (int i = sizea - 1; p - i < sizeb;i--) {
                sum += a[i] * b[p - i];
            }
            c[p] = sum;
        }
        nc[0] = c[0] % scale;
        for (int i = 1; i < sizec; i++) {
            c[i] += c[i - 1] / scale;
            nc[i] = c[i] % scale;
        }
        nc[sizec] = c[sizec - 1] / scale;
        if (nc[sizec])
            cout << nc[sizec];
        for (int i = sizec - 1; i >= 0; i--) {
            cout << nc[i];
        }
        cout << '\n';
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #155.511 ms332 KBAcceptedScore: 100


Judge Duck Online | 评测鸭在线
Server Time: 2022-10-05 07:56:28 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用