#include "stdafx.h"
#include "iostream"
using namespace std;
int count(char *s)//判断字符串大小
{
int count1=0;
char ch;
ch=*s;
while(ch!='/0')
{
count1++;
s++;
ch=*s;
}
return count1;
}
int *zh1(char *s,int count1)
{
char ch;
int i,*array1;
array1=new int[count1];
ch=*s;//cout<<ch;测试
for(i=0;i<count1;i++)
{
//cout<<ch<<endl;//看下这一行为何没有输出?
*(array1+count1-i-1)=ch-'0';
s++;
ch=*s;
}
for(i=0;i<count1;i++)
cout<<array1[i];
cout<<endl;///测试
return array1;
}
void zh2(int a[],int m)
{
char *s;
int i;
cout<<"看作实数:";
for(i=m-1;i>=0;i--)
{
cout<<a[i];
}
cout<<endl;
}
int *jisuan(int *a,int m,int *b,int n)
{
int *array3;
array3=new int[m+n];
for(int l=0;l<m+n;l++)
array3[l]=0;
int i,j,k;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
if(a[i]*b[j]<10)
array3[i+j]=array3[i+j]+a[i]*b[j];
else
{
array3[i+j]=array3[i+j]+a[i]*b[j]%10;
array3[i+j+1]=array3[i+j+1]+(a[i]*b[j]-a[i]*b[j]%10)/10;
}
for(int l=0;l<m+n;l++)
if(array3[l]>=10)
{
array3[l+1]=array3[l+1]+(array3[l]-array3[l]%10)/10;
array3[l]=array3[l]%10;//必须立马进位
}
}
cout<<"倒序输出:";
for(int l=0;l<m+n;l++)//测试
cout<<array3[l];
cout<<endl;
/*for(int l=0;l<m+n;l++)
{
if(array3[l]>=10)
{
array3[l+1]=array3[l+1]+(array3[l]-array3[l]%10)/10;
array3[l]=array3[l]%10;
}
cout<<array3[l];
}*/
return array3;
}
int _tmain(int argc, _TCHAR* argv[])
{
char *a1={"4545446647465354654956565659/0"},*a2={"54787867635464897654458458475454545454545454/0"};
int n1,n2,*b1,*b2,*shu;
n1=count(a1);
n2=count(a2);
cout<<"输入乘数1的位数:"<<n1<<endl;
cout<<"输入乘数2的位数:"<<n2<<endl;
b1=new int[n1];
b1=zh1(a1,n1);
b2=new int[n2];
b2=zh1(a2,n2);
shu=new int[n1+n2];
shu=jisuan(b1,n1,b2,n2);
//for(int i=0;i<n;i++)测试用
// cout<<b[i];
//char *s;
zh2(shu,n1+n2);
//puts(s);测试用
//cout<<endl;
delete[] b1;
delete[] b2;
delete[] shu;
return 0;
}