提交记录 18049


用户 题目 状态 得分 用时 内存 语言 代码长度
JOJO 1004a. 【模板题】高精度乘法2 Accepted 100 1.277 ms 432 KB C++ 1.83 KB
提交时间 评测时间
2022-09-19 21:54:12 2022-09-19 21:54:13
#include <stdio.h>
#include <string.h>
typedef unsigned long long ll;
#define MOD 100000000

struct HP{
    ll num[10000];
    int len;
};

void mul(struct HP x, struct HP y, struct HP *dst) {
    dst->len = x.len + y.len - 1;
    for (int i = 0; i < dst->len; ++i) {
        dst->num[i] = 0;
    }
    for (int i = 0; i < x.len; ++i) {
        for (int j = 0; j < y.len; ++j) {
            dst->num[i + j] += x.num[i] * y.num[j];
        }
    }
    for (int i = 0; i < dst->len - 1; ++i) {
        if (dst->num[i] > MOD) {
            dst->num[i + 1] += dst->num[i] / MOD;
            dst->num[i] = dst->num[i] % MOD;
        }
    }
}

int main() {
    struct HP a, b, c;
    char buf[10024];
    scanf("%s", buf);
    int pos = -1;
    ll count = 1;
    for (int i = strlen(buf) - 1; i >= 0; --i) {
        if (count == 1) {
            pos++;
            a.num[pos] = (int)buf[i] - 48;
            count *= 10;
        }
        else {
            a.num[pos] += ((int)buf[i] - 48) * count;
            count *= 10;
            if (count == MOD) count = 1;
        }
    }
    a.len = pos + 1;
    scanf("%s", buf);
    pos = -1;
    count = 1;
    for (int i = strlen(buf) - 1; i >= 0; --i) {
        if (count == 1) {
            pos++;
            b.num[pos] = (int)buf[i] - 48;
            count *= 10;
        }
        else {
            b.num[pos] += ((int)buf[i] - 48) * count;
            count *= 10;
            if (count == MOD) count = 1;
        }
    }
    #ifdef DEBUG
     printf("a.len = %d\n", a.len);
     printf("a = %d", a.num[a.len - 1]);
     for (int i = a.len - 2; i >= 0; --i) {
         printf("%08d", a.num[i]);
     }
     printf("\n");
    #endif
    b.len = pos + 1;
    mul(a, b, &c);
    printf("%lld", c.num[c.len - 1]);
    for (int i = c.len - 2; i >= 0; --i) {
        printf("%08ld", c.num[i]);
    }
    printf("\n");
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.277 ms432 KBAcceptedScore: 100


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