本文目录
#include"high_precision_t.h"

intmain(intargc,char*argv[]){ High_Precision_Ta("123.01234567890456789");High_Precision_Tb("-789.01234567890123456");

//cin>>a>>b;cout<<"a="<<a<<"\nb="<<b<<endl;
High_Precision_Tc=a+b;cout<<"a+b="<<c<<endl;
c=a-b;cout<<"a-b="<<c<<endl;
c=a*b;cout<<"a*b="<<c<<endl;
return0;}
//high_precision_t.h
#ifndefhigh_precision_tH#definehigh_precision_tH#include<iostream>#include<sstream.h>
classHigh_Precision_T{ private:unsigneddigits[20];unsigneddecpt;charsign;
voidStringToDigits(stringstr);public:High_Precision_T();
High_Precision_T(doubled);
High_Precision_T(stringd);
operatordouble();operatorstring();
High_Precision_Toperator+(constHigh_Precision_T&op);
High_Precision_Toperator-(constHigh_Precision_T&op);
High_Precision_Toperator*(constHigh_Precision_T&op);
friendistream&operator>>(istream&is,High_Precision_T&op){ stringstr;is>>str;op=High_Precision_T(str);returnis;}
friendostream&operator<<(ostream&os,High_Precision_T&op){ os<<string(op);returnos;}
};
#endif
//high_precision_t.cpp
High_Precision_T::High_Precision_T(){ memset(digits,0,20*sizeof(unsigned));sign='+';decpt=1;}
High_Precision_T::High_Precision_T(doubledata){ stringstreamss;stringstr;ss<<data;ss>>str;
StringToDigits(str);}
High_Precision_T::High_Precision_T(stringstr){ StringToDigits(str);}
voidHigh_Precision_T::StringToDigits(stringstr){ memset(digits,0,20*sizeof(unsigned));sign='+';decpt=1;
//过滤串前非数字字符intpos;for(pos=0;pos<str.length();pos++){ if(str[pos]=='+'||str[pos]=='-'||str[pos]=='.'||(str[pos]>='0'&&str[pos]<='9')){ break;}}str.erase(0,pos);
//处理符号位if(str[0]=='+'||str[0]=='-'){ //首位是符号位sign=str[0];str.erase(0,1);}else{ sign='+';}
//过滤串后非数字字符for(pos=0;pos<str.length();pos++){ if(str[pos]!='.'&&!(str[pos]>='0'&&str[pos]<='9')){ break;}}str.erase(pos);
//小数点前重复的零//pos=str.find_first_of('.');while(str[0]=='0'){ str.erase(0,1);}
//处理小数点pos=str.find_first_of('.');if(pos>=0){ str.erase(pos,1);decpt=pos;
//还有小数点?pos=str.find_first_of('.');if(pos>=0)str.erase(pos);}
//合法数字for(unsignedi=0;i<str.length()&&i<20;++i){ digits[i]=str[i]-48;}
}
High_Precision_T::operatordouble(){ return0.0;}
High_Precision_T::operatorstring(){ stringstreamss;stringstr;if(sign=='-')ss<<'-';for(inti=0;i<decpt;i++)ss<<digits[i];ss<<'.';for(inti=decpt;i<20;i++)ss<<digits[i];ss>>str;returnstr;}//---------------------------------------------------------------------------High_Precision_THigh_Precision_T::operator+(constHigh_Precision_T&op){
//辅助变量intint_len=decpt>=op.decpt?decpt:op.decpt;//和的整数长度intdec_len=decpt>=op.decpt?20-op.decpt:20-decpt;//和的小数长度
//临时空间int*temp_digits=newint[int_len+dec_len+1];//temp_digits[0]为进位。memset(temp_digits,0,(int_len+dec_len+1)*sizeof(int));inttemp_decpt=int_len+1;//inttemp_sign='+';//默认为正数
intdif=temp_decpt-this->decpt;//小数点对齐后,卡的卡机数组下标的钱过差值intopdif=temp_decpt-op.decpt;
intaugend;intaddend;
//从**位开始相加for(inti=int_len+dec_len;i>0;i--){ //被加数augend=((i-dif)>-1&&(i-dif)<20)?this->digits[i-dif]:0;(this->sign=='+')?temp_digits[i]+=augend:temp_digits[i]-=augend;
//加数addend=((i-opdif)>-1&&(i-opdif)<20)?op.digits[i-opdif]:0;(op.sign=='+')?temp_digits[i]+=addend:temp_digits[i]-=addend;
//确保每位为0~9内的非负值while(temp_digits[i]<0){ //处理借位temp_digits[i-1]-=1;//借位temp_digits[i]+=10;}if(temp_digits[i]>9){ //处理进位temp_digits[i-1]+=1;//进位temp_digits[i]-=10;}}
if(temp_digits[0]<0){ //进位为负,则整个数为负数temp_sign='-';for(inti=int_len+dec_len;i>0;i--){ temp_digits[i]=-temp_digits[i];if(temp_digits[i]<0){ temp_digits[i-1]+=1;//借位temp_digits[i]+=10;}}temp_digits[0]=-temp_digits[0];}//
High_Precision_Ttemp;if(temp_digits[0]>0&&temp_decpt<20){ //未处理溢出。temp_decpt>20有溢出temp.sign=temp_sign;temp.decpt=temp_decpt;memcpy(temp.digits,temp_digits,20*sizeof(int));}else{ temp.sign=temp_sign;temp.decpt=temp_decpt-1;memcpy(temp.digits,&temp_digits[1],20*sizeof(int));}
delete[]temp_digits;returntemp;}
High_Precision_THigh_Precision_T::operator-(constHigh_Precision_T&op){ High_Precision_Ttemp=op;temp.sign=op.sign=='+'?'-':'+';return*this+temp;}
High_Precision_THigh_Precision_T::operator*(constHigh_Precision_T&op){
//辅助空间inttemp_digits[41];//temp_digits[0]为进位。滤刷memset(temp_digits,0,41*sizeof(int));inttemp_decpt=decpt+op.decpt+1;//
intk=0;for(inti=19;i>=0;i--){ for(intj=19;j>=0;j--){ k=i+j+2;temp_digits[k]+=digits[i]*op.digits[j];//temp_digits[k-1]+=temp_digits[k]/10;temp_digits[k]%=10;}}
High_Precision_Ttemp;temp.sign=(sign==op.sign)?'+':'-';
k=0;while(k<40){ if(temp_digits[k]!=0)break;k++;}if(k>0){ temp.decpt=temp_decpt-k;memcpy(temp.digits,&temp_digits[k],20*sizeof(int));}returntemp;
银行卡鉴权94是好多什么意思关于这个问题,银行卡鉴权94通常是刷少钱指银行卡验证的一种方式,其中94是卡的卡机代表银行卡的验证结果代码。这种验证方式通常用于网上支付、钱过手机支付、滤刷POS机刷卡等场景中,好多旨在确认用户所提供的刷少钱银行卡信息是否正确和有效。
如果银行卡鉴权返回94,卡的卡机则表示银行卡验证成功,钱过可以进行后续的滤刷交易操作。
好多