一晚上终于艹出了一个高精度模板。。。T_T
还是java大数好。
/****************************
* author:crazy_石头
* date:2014/04/30
* time: ms
* algorithm:高精度
* Pro:UVA
***************************/
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; #define INF INT_MAX #define eps 1e-8 #define A system("pause") #define rep(i,h,n) for(int i=(h);i<=(n);i++) #define ms(a,b) memset((a),(b),sizeof(a)) #define lson l , m , rt << 1 #define rson m + 1 , r , rt << 1 | 1 #define LL long long const int maxn=100+5; const int maxm=30; char a[maxn],b[maxn]; inline void Plus(char *a,char *b) { char shit[maxn]; int len1=strlen(a); int len2=strlen(b); int holyshit; if(len1>len2) { holyshit=len1-len2; for(int i=len2-1;i>=0;i--) b[i+holyshit]=b[i]; for(int i=0;i<=len1-len2-1;i++) b[i]='0'; } else if(len2>len1) { holyshit=len2-len1; for(int i=len1-1;i>=0;i--) b[i+holyshit]=b[i]; for(int i=0;i<=len2-len1-1;i++) b[i]='0'; } int len=std::max(len1,len2); int c=0,k=0; for(int i=len-1;i>=0;i--) { c=(a[i]-'0'+b[i]-'0')+c/10; shit[k++]=c%10+'0'; } if(c>=10) shit[k++]='1'; shit[k]='\0'; for(int i=k-1;i>=0;i--) printf("%c",shit[i]); printf("\n"); } inline void Minus(char *a,char *b) { char shit[maxn]; int len1=strlen(a); int len2=strlen(b); int k; if(len1>=len2) { k=len1-len2; for(int i=len2-1;i>=0;i--) b[i+k]=b[i]; for(int i=0;i<=len1-len2-1;i++) b[i]='0'; } int len=std::max(len1,len2); /*for(int i=0;i
=0;i--) { int fuckin=(a[i]-'0')-(b[i]-'0'); if(fuckin<0) { shit[cnt++]=fuckin+10+'0'; int cao=a[i-1]-'0'; printf("cao==%d\n",cao); cao--; printf("cao==%d\n",cao); a[i-1]=cao+'0'; } else shit[cnt++]=fuckin+'0'; } shit[cnt]='\0'; int i=cnt-1; while(shit[i]=='0'&&i>0) i--; for(int j=i;j>=0;j--) printf("%c",shit[j]); printf("\n"); } inline void multiply(char* a,char* b) { char c[maxn]; int i,j,ca,cb,*s; ca=strlen(a); cb=strlen(b); s=(int*)malloc(sizeof(int)*(ca + cb)); for(i=0;i<=ca+cb-1;i++) s[i]=0; for (i=0;i
=0;i--) { if(s[i]>=10) { s[i-1]+=s[i]/10; s[i]%=10; } } i=0; while(s[i] == 0) i++; for(j=0;i
len2) Minus(a,b); else { printf("-"); Minus(b,a); }*/ multiply(a,b); } return 0; } * This source code was highlighted by YcdoiT. ( style: Autumn )