#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[10088],b[10087],c[10087];
string mem("0123456789ABCDEF");
bool check_(string a,string b){
if(a.length()>b.length())return 1;
if(b.length()>a.length())return 0;
for(int i=0;i<a.length();i++){
if(a[i]>b[i])return 1;
if(a[i]<b[i])return 0;
}
return 1;
}
int search_(char x){
for(int i=0;i<mem.length();i++){
if(mem[i]==x){
return i;
}
}
}
string sub_(string x,string y){
string ans="";
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
if(!check_(x,y))swap(x,y);
int xl=x.length(),yl=y.length(),p=max(xl,yl);
for(int i=xl-1,j=1;i>=0;i--,j++)a[j]=search_(x[i]);
for(int i=yl-1,j=1;i>=0;i--,j++)b[j]=search_(y[i]);
for(int i=1;i<=p;i++){
if(i!=p){
a[i]+=10;
a[i+1]--;
}
c[i]=a[i]-b[i];
}
for(int i=1;i<p;i++){
c[i+1]+=(c[i]/10);
c[i]=c[i]%10;
}
for(;!c[p];)p--;
for(int i=p;i>=1;i--)ans+=mem[c[i]];
if(ans.empty())return "0";
return ans;
}
string mult_(string x,string y){
if(x=="0"||y=="0")return "0";
string ans;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
int xl=x.length(),yl=y.length(),p=xl+yl;
for(int i=1,j=xl-1;i<=xl;i++,j--)a[i]=search_(x[j]);
for(int i=1,j=yl-1;i<=yl;i++,j--)b[i]=search_(y[j]);
for(int i=1;i<=yl;i++){
for(int j=1;j<=xl;j++){
c[j+i-1]+=(a[j]*b[i]);
}
}
for(int i=2;i<=p;i++){
c[i]+=(c[i-1]/10);
c[i-1]=c[i-1]%10;
}
for(;!c[p];)p--;
for(int i=p;i>=1;i--)ans+=mem[c[i]];
return ans;
}
string and_(string x,string y,int n){
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
int xl=x.length(),yl=y.length(),p=max(xl,yl);
for(int i=xl-1,j=1;i>=0;i--,j++)a[j]=search_(x[i]);
for(int i=yl-1,j=1;i>=0;i--,j++)b[j]=search_(y[i]);
for(int i=1;i<=p+1;i++)c[i]=a[i]+b[i];
for(int i=2;i<=p+1;i++){
c[i]+=(c[i-1]/n);
c[i-1]=c[i-1]%n;
}
p++;
for(;!c[p];)p--;
string ans="";
for(int i=p;i>=1;i--)ans+=mem[c[i]];
return ans;
}
标签:return,string,高精度,int,加减,--,length,ans
From: https://www.cnblogs.com/wertyuio1/p/18365258