/*
* Author: dengzhaoqun
* Date: 2011/04/11
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LENGTH 1000
//------------define the data struct--------------------
typedef struct
{
char *cptr;
int len;
}CharNum;
//------------the end of defining data struct----------
//------the methods' declaration------
void DelHeadZero(CharNum *Result);
CharNum *DoMinus(CharNum *A,CharNum *B,int *flag);
int GetMax(int x,int y);
int GetMin(int x,int y);
CharNum *GetNum(char ch);
void Init(char *ch,int len);
CharNum *Merge(CharNum *AC,CharNum *BD,CharNum *ABDC,int k,int flagABDC);
void MergeAdd(CharNum *des,CharNum *source,int k);
void MergeMinus(CharNum *des,CharNum *source,int k);
CharNum *Multiple(CharNum *X,CharNum *Y);
void ShowCharNum(CharNum *Result);
void ToChars(int mul,CharNum *Result);
void TopDown(CharNum *chN);
char *ToStr(CharNum *chN);
//----end of method declaration-----
//-------------the main method--------------
int main()
{
CharNum *X;
CharNum *Y;
CharNum *Result;
//init
X=NULL;
Y=NULL;
Result=NULL;
//get X,Y
X=GetNum('X');
Y=GetNum('Y');
Result=Multiple(X,Y);
ShowCharNum(Result);
free(X);
free(Y);
free(Result);
getchar();
return 0;
}
//------------------the end of main method------------------
//-----------begin the method of TopDown---------------
void TopDown(CharNum *chN)
{
int i;
int j;
int k;
char *ch;
j=chN->len-1;
while(chN->cptr[j]!='#')
{
j--;
}
ch=(char *)malloc(j*sizeof(char));
k=j-1;
i=0;
for(i,k;i<j;k--,i++)
{
ch[i]=chN->cptr[k];
}
i=0;
for(i;i<j;i++)
{
chN->cptr[i]=ch[i];
}
free(ch);
}
//-----------end of method TopDown--------------
//-----------implement the method of getNum-------------
CharNum *GetNum(char ch)
{
CharNum *chN;
chN=(CharNum *)malloc(sizeof(CharNum));
chN->cptr=NULL;
chN->len=0;
chN->cptr=(char *)malloc(MAX_LENGTH*sizeof(char));
Init(chN->cptr,MAX_LENGTH);
chN->len=MAX_LENGTH;
printf("Input the value of %c(length<=)",ch);
printf("%d"
大数相乘(分治法实现时间复杂度为O(n^1.59))
最新推荐文章于 2020-11-21 16:54:00 发布