提交记录 16499


用户 题目 状态 得分 用时 内存 语言 代码长度
lambda 1004. 【模板题】高精度乘法 Time Limit Exceeded 0 3 s 4940 KB C++ 1.28 KB
提交时间 评测时间
2021-09-21 17:00:42 2021-09-21 17:00:47
#include <iostream>
#include <cstdio>
#include <cstring>

#define MAX_LEN 1000000
#define MAX_RES (MAX_LEN * 2 + 1)

using namespace std;

void inline num(char* buf, char* res) {
    int len = strlen(buf);
    for(int i = 0; i < len; ++i){
        res[len - i - 1] = buf[i] - '0';
    }
}

void inline print_res(char* res, int top) {
    while(top > -1){
        printf("%d", res[top]);
        top--;
    }
    printf("\n");
}

void multiplication(){
    char a[MAX_LEN + 1], b[MAX_LEN + 1], res[MAX_RES], buf[MAX_LEN + 1];
    int cur_a, cur_b, tmp, max_res;
    cin>>buf;
    int len_a = strlen(buf);
    num(buf, a);
    cin>>buf;
    int len_b = strlen(buf);
    num(buf, b);
    memset(res, 0, sizeof(char) * MAX_RES);
    for(cur_b = 0; cur_b < len_b; cur_b++){
        for(cur_a = 0; cur_a < len_a; cur_a++){
            tmp = a[cur_a] * b[cur_b] + res[cur_b + cur_a];
            res[cur_b + cur_a] = tmp % 10;
            res[cur_b + cur_a + 1] += tmp / 10;
        }
    }
    max_res = len_a + len_b;
    while(max_res != -1 && res[max_res] == 0) max_res--;
    if(max_res == -1){
        max_res = 0;
    }
    print_res(res, max_res);
}

int main(){
    int n;
    cin >> n;
    ios::sync_with_stdio(false);
    for(int rnd = 0; rnd < n; rnd++){
        multiplication();
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #13 s4 MB + 844 KBTime Limit ExceededScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-03-19 02:53:23 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠