#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
using namespace std;
string Hadd(string A, string B) {
int Len = max(A.size(), B.size());
int a[256] = { 0 }, b[256] = { 0 };
for (int i = A.size() - 1; i >= 0; i--) {
a[A.size() - 1 - i] = A[i]-48;
}
for (int i = B.size() - 1; i >= 0; i--) {
b[B.size() - 1 - i] = B[i] - 48;
}
int temp[257] = { 0 };
for (int i = 0; i < Len; i++) {
temp[i] += a[i] + b[i];
temp[i + 1] = temp[i] / 10;
temp[i] = temp[i] % 10;
}
string ans;
for (int i = Len; i >= 0; i--) {
if (i == Len && temp[i] == 0)continue;
ans += temp[i] + 48;
//cout << temp[i];
}
return ans;
}
string Hmul(string A, string B) {//高精度乘法
int Len = max(A.size(), B.size());
int a[256] = { 0 }, b[256] = { 0 };
for (int i = A.size() - 1; i >= 0; i--) {//逆位存储
a[A.size() - 1 - i] = A[i] - 48;
}
for (int i = B.size() - 1; i >= 0; i--) {
b[B.size() - 1 - i] = B[i] - 48;
}
int temp[512] = {0};
for (int i = 0; i <= A.size() - 1; i++) {
for (int j = 0; j <= B.size() - 1; j++) {//运算部分
temp[i + j] += a[i] * b[j];
int n = i + j;
while (temp[n] >= 10) {
temp[n + 1] = temp[n] / 10;//每一步都控制每一位均为个位数
temp[n] = temp[n] % 10;
n++;
}
}
}
string ans;
int f = 1;
for (int i = 511; i >= 0; i--) {
if (temp[i] == 0 && f == 1) {//除去先导0
continue;
}
else {
f = 0;
}
ans += temp[i] + 48;//将答案填入字符串
//cout << temp[i];
}
return ans;
}
int main() {
cout << Hmul("1144", "1910");
return 0;
}
非常感谢大佬 例如如果我输入1145141919810的话,答案与计算器的结果不同,而如果输入1111则答案为121,求助。