1 solutions
-
-1
这道题非常难 主要考察对算数运算符的理解
在数学里乘法就是求几个相同加数的和的简便运算。例如,3 个 5 相加可表示为\(5×3=15\),这里 “×” 是乘号,乘号两边的数称为因数,结果称为积,乘法是加法的高级运算。如\(4×6\)表示 6 个 4 相加,即\(4+4+4+4+4+4=24\)
以下是一个非常基础的做法-高精度
时间:34ms 内存:816 KiB 长度:909 Bytes
这是代码实现
#define NDEBUG #import <bits/stdc++.h> #ifdef __linux__ using namespace std; using std::cin, std::cout; using i64 = signed long long; #define false 0 typedef signed long long IntPtr; IntPtr n; const i64 N = 1e3 + 10; i64 a[N], b[N], ans[N]; i64 la, lb, len; void read(i64 *a, i64 &len) { string s; cin >> s; len = s.size(); for (i64 i = 0; i < len; i++) a[i] = s[i] - 48; reverse(a, a + len); } #endif main(i64) { #ifdef __linux__ std::ios(false), cin.tie(nullptr), cout.tie(nullptr); ios::sync_with_stdio(0); cin.tie(nullptr); read(a, la); read(b, lb); len = la + lb - 1; for (i64 i = 0; i < la; i++) for (i64 j = 0; j < lb; j++) ans[i + j] += a[i] * b[j]; for (i64 i = 0; i < len; i++) if (ans[i] > 9) ans[i + 1] += ans[i] / 10, ans[i] %= 10; while (ans[len]) len++; for (i64 i = len - 1; i >= 0; --i) cout << ans[i]; #endif return false; } /* 1 2 2 2 3 6 200 300 60000 */
Information
- ID
- 11994
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 1
- Tags
- # Submissions
- 54
- Accepted
- 25
- Uploaded By