加法
//优化后的高精度加法
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
int* g_lbs;
int* g_rbs;
int* g_result;
void run () 
...{
//接受输入
std::string lbs;
std::string rbs;
std::cout<<"Please input the lbs number: ";
std::cin>>lbs;
std::cout<<"And input the rbs number: ";
std::cin>>rbs;
//调整
int lenLbs=lbs.length();
int lenRbs=rbs.length();
if (lenLbs<lenRbs) 
...{
std::swap(lbs, rbs);
std::swap(lenLbs, lenRbs);
}
//初始化数组
int sizeLbs=lenLbs%4==0?lenLbs/4:lenLbs/4+1;
int sizeRbs=lenRbs%4==0?lenRbs/4:lenRbs/4+1;
g_lbs=new int[sizeLbs];
g_rbs=new int[sizeRbs];
int i,j;
for (i=0; i<sizeLbs; ++i) 
...{
g_lbs[i]=0;
}
for (j=0; j<sizeRbs; ++j) 
...{
g_rbs[j]=0; 
}
std::string str;
//字符串到数组转化
int count=0;
while (lbs.length()>=4) 
...{
str=lbs.substr(lbs.length()-4);
lbs.erase(lbs.length()-4);
g_lbs[count]=atoi(str.c_str());
++count;
}
if (!lbs.empty()) 
...{
str=lbs;
lbs.clear();
g_lbs[count]=atoi(str.c_str());
}
count=0;
while (rbs.length()>=4) 
...{
str=rbs.substr(rbs.length()-4);
rbs.erase(rbs.length()-4);
g_rbs[count]=atoi(str.c_str());
++count;
}
if (!rbs.empty()) 
...{
str=rbs;
rbs.clear();
g_rbs[count]=atoi(str.c_str());
}
//初始化结果数组
g_result=new int[sizeLbs+1];
for (i=0; i<=sizeLbs; ++i) 
...{
g_result[i]=0;
}
//加法运算
for (j=0; j<sizeLbs; ++j) 
...{
if (j<sizeRbs) 
...{
g_result[j]+=g_lbs[j]+g_rbs[j];
} 
else 
...{
g_result[j]+=g_lbs[j];
}
g_result[j+1]+=g_result[j]/10000;
g_result[j]%=10000;
}
//输出
i=sizeLbs;
while (!g_result[i]) 
...{
--i;
if (i==-1) 
...{
std::cout<<"Result is 0"<<std::endl;
return;
}
}
std::cout<<"Result is "<<g_result[i--];
for (j=i; j>=0; --j) 
...{
if (g_result[j]<1000) 
...{
std::cout<<'0';
}
if (g_result[j]<100) 
...{
std::cout<<'0';
}
if (g_result[j]<10) 
...{
std::cout<<'0';
}
std::cout<<g_result[j];
}
std::cout<<std::endl;
}
int main(int argc, char *argv[]) 
...{
run(); //运行
//释放内存
delete[] g_lbs; 
delete[] g_rbs;
delete[] g_result;
return 0;
}
减法
//优化后的高精度减法
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
int* g_lbs;
int* g_rbs;
int* g_result;
void run () 
...{
bool positive=true;
//接受输入
std::string lbs;
std::string rbs;
std::cout<<"Please input the lbs number: ";
std::cin>>lbs;
std::cout<<"And input the rbs number: ";
std::cin>>rbs;
//调整
int lenLbs=lbs.length();
int lenRbs=rbs.length();
if (lenLbs<lenRbs || lbs<rbs) 
...{
positive=false;
std::swap(lbs, rbs);
std::swap(lenLbs, lenRbs);
}
//初始化数组
int sizeLbs=lenLbs%4==0?lenLbs/4:lenLbs/4+1;
int sizeRbs=lenRbs%4==0?lenRbs/4:lenRbs/4+1;
g_lbs=new int[sizeLbs];
g_rbs=new int[sizeRbs];
int i,j;
for (i=0; i<sizeLbs; ++i) 
...{
g_lbs[i]=0; 
}
for (j=0; j<sizeRbs; ++j) 
...{
g_rbs[j]=0;
}
std::string str;
//字符串到数组转化
int count=0;
while (lbs.length()>=4) 
...{
str=lbs.substr(lbs.length()-4);
lbs.erase(lbs.length()-4);
g_lbs[count]=atoi(str.c_str());
++count;
}
if (!lbs.empty()) 
...{
str=lbs;
lbs.clear();
g_lbs[count]=atoi(str.c_str());
}
count=0;
while (rbs.length()>=4) 
...{
str=rbs.substr(rbs.length()-4);
rbs.erase(rbs.length()-4);
g_rbs[count]=atoi(str.c_str());
++count;
}
if (!rbs.empty()) 
...{
str=rbs;
rbs.clear();
g_rbs[count]=atoi(str.c_str());
}
//初始化结果数组
g_result=new int[sizeLbs+1];
for (i=0; i<=sizeLbs; ++i) 
...{
g_result[i]=0;
}
//减法运算
for (j=0; j<sizeLbs; ++j) 
...{ 
if (j<sizeRbs) 
...{
if (g_lbs[j]-g_rbs[j]<0) 
...{
--g_lbs[j+1];
g_lbs[j]+=10000;
}
g_result[j]=g_lbs[j]-g_rbs[j];
}
else 
...{
g_result[j]=g_lbs[j];
}
}
//输出
i=sizeLbs;
while (!g_result[i]) 
...{
--i;
if (i==-1) 
...{
std::cout<<"Result is 0"<<std::endl;
return;
}
}
std::cout<<"Result is "<<(positive?"":"-")<<g_result[i--];
for (j=i; j>=0; --j) 
...{
if (g_result[j]<1000) 
...{
std::cout<<'0';
}
if (g_result[j]<100) 
...{
std::cout<<'0';
}
if (g_result[j]<10) 
...{
std::cout<<'0';
}
std::cout<<g_result[j];
}
std::cout<<std::endl;
} 
int main(int argc, char *argv[]) 
...{
run(); //运行
//释放内存
delete[] g_lbs;
delete[] g_rbs;
delete[] g_result;
return 0;
}
乘法
//优化后的高精度乘法
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
int* g_lbs;
int* g_rbs;
int* g_result;
void run () 
...{
//接受输入
std::string lbs;
std::string rbs;
std::cout<<"Please input the lbs number: ";
std::cin>>lbs;
std::cout<<"And input the rbs number: ";
std::cin>>rbs;
int lenLbs=lbs.length();
int lenRbs=rbs.length();
//初始化数组
int sizeLbs=lenLbs%4==0?lenLbs/4:lenLbs/4+1;
int sizeRbs=lenRbs%4==0?lenRbs/4:lenRbs/4+1;
g_lbs=new int[sizeLbs+1];
g_rbs=new int[sizeRbs+1];
int i,j;
for (i=0; i<=sizeLbs; ++i) 
...{
g_lbs[i]=0;
} 
for (j=0; j<=sizeRbs; ++j) 
...{
g_rbs[j]=0;
}
std::string str;
//字符串到数组转化
int count=1;
while (lbs.length()>=4) 
...{
str=lbs.substr(lbs.length()-4);
lbs.erase(lbs.length()-4);
g_lbs[count]=atoi(str.c_str());
++count;
}
if (!lbs.empty()) 
...{
str=lbs;
lbs.clear();
g_lbs[count]=atoi(str.c_str());
}
count=1;
while (rbs.length()>=4) 




