高精度四则运算之加法实现——参考ACM/ICPC程序设计与分析(c++实现)chapter4

 1 #include <cstdlib>
 2 #include <iostream>
 3 #include <algorithm>
 4 
 5 using namespace std;
 6 const int MAXLEN=100;
 7 
 8 int*Str2Int(char*str)
 9 {
10   int i,len=strlen(str);
11   int*a=new int[(len+1)*sizeof(int)];
12   for(i=0;i<len;i++) a[i]=(int)str[len-i-1]-48;
13   return a;
14 }
15 
16 int check(int* a,int n)//规整 
17 {
18    int k=0,len=n;
19    while(a[len-1]==0&&len>1) len--;
20    for(k=0;k<len;k++)
21    {
22       if(a[k]>=10)
23       {
24           a[k+1]=a[k+1]+a[k]/10;
25           a[k]=a[k]%10;
26       } 
27    
28    }
29    if(a[k]!=0) len=k+1;
30    return len;
31     
32 }
33 
34 char* Int2Str(int* a,int n)
35 {
36    int i;
37    char* str=new char[(n+1)*sizeof(char)];
38    for(i=0;i<n;i++) str[i]=(char)a[n-i-1]+48;
39    str[n]='