提交记录 17274
提交时间 |
评测时间 |
2022-01-21 22:46:00 |
2022-01-21 22:46:02 |
#include <bits/stdc++.h>
static const int Len = 1e4 + 5;
struct BigInt
{
static const int Bit = 9;
static const long long Mod = 1000000000;
long long s[Len], c;
bool flag;
BigInt operator = (const char *num)
{
memset(s, 0, sizeof(s)); flag = (num[0] != 45);
int l = strlen(num);
c = 0;
for (int i = l - 1; i >= int(!flag); i -= Bit)
{
c++;
long long w = 1;
for (int j = i; j > i - Bit && j >= int(!flag); j--)
{
s[c] += (num[j] ^ 48) * w;
w = (w << 1) + (w << 3);
}
}
return *this;
}
BigInt operator = (const long long num)
{
char a[Len];
sprintf(a, "%lld", num);
*this = a;
return *this;
}
BigInt() { memset(s, 0, sizeof(s)); c = 1; }
BigInt(const char *num) { *this = num; }
BigInt(long long num) { *this = num; }
friend BigInt _multiply(const BigInt &a, const BigInt &b)
{
BigInt c;
c.c = a.c + b.c;
for (int i = 1; i <= a.c; i++)
{
long long x = 0;
for (int j = 1; j <= b.c; j++)
{
int k = i + j - 1;
c.s[k] += a.s[i] * b.s[j] + x;
x = c.s[k] / Mod;
c.s[k] %= Mod;
}
c.s[i + b.c] = x;
}
while (c.s[c.c] > 0) { c.c++; }
while (c.s[c.c] == 0 && c.c > 1) { c.c--; }
return c;
}
friend BigInt operator * (const BigInt &a, const BigInt &b)
{
BigInt c;
if (a.flag ^ b.flag) { c = _multiply(a, b); c.flag = false; }
else { c = _multiply(a, b); c.flag = true; }
return c;
}
BigInt operator *= (const BigInt &a)
{
*this = *this * a;
return *this;
}
};
std::ostream& operator << (std::ostream &out, const BigInt &a)
{
if (!a.flag) putchar(45);
printf("%lld", a.s[a.c]);
for (int i = a.c - 1; i >= 1; i--) { printf("%09lld", a.s[i]); }
return out;
}
std::istream& operator >> (std::istream &in, BigInt &a)
{
char s[Len];
in >> s;
a = s;
return in;
}
int main()
{
BigInt a, b;
std::cin >> a >> b;
std::cout << a * b;
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 3.414 ms | 372 KB | Accepted | Score: 100 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-10-05 12:08:23 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用