提交记录 18049
提交时间 |
评测时间 |
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;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 1.277 ms | 432 KB | Accepted | Score: 100 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-10-05 10:54:44 | Loaded in 0 ms | Server Status
个人娱乐项目,仅供学习交流使用