超長正整數的加法源代碼
大小:155 人氣: 2010-02-09 需要積分:0
標簽:源代碼(65730)
超長正整數的加法源代碼方法一:
#include
#include
#include
typedef struct node
{ int data;
? struct node *next;
}LinkList;
void Create(LinkList *&head,char str[])
{ LinkList *s;
? int i=0,j,k,len,x=0,n; char ch;
? head=(LinkList *)malloc(sizeof(LinkList));
? head->next=head;
? len=strlen(str);
? n=len%4;? ch=str[i];
? s=(LinkList *)malloc(sizeof(LinkList));
? for(j=0; j
??? i++;
?ch=str[i];
? }
? s->data=x;
? s->next=head->next;
? head->next=s;
? n=len/4;
? for (j=0; j
??? x=0;
?for (k=0; k<4; k++)
?{ x=x*10+ch-'0';
?? i++;
?? ch=str[i];
?}
?s->data=x;
?s->next=head->next;
?head->next=s;
? }
}
void Output(LinkList *head)
{ LinkList *p;
? p=head->next;
? while(p!=head)
? { cout<
??? p=p->next;
? }
? cout<
void NiOrder(LinkList *&head)
{ LinkList *p,*r;
? p=head->next;
? if (p!=head)
? { r=p->next;
??? p->next=head;
?p=r;
?while (p!=head)
?{ r=p->next;
?? p->next=head->next;
?? head->next=p;
?? p=r;
?? r=p->next;
?}
? }
}
void AddLink(LinkList *h1,LinkList *h2,LinkList *&h)
{ LinkList *p1,*p2,*s,*r;
? int tag=0;
? p1=h1->next; p2=h2->next;
? h=(LinkList *)malloc(sizeof(LinkList));
? h->next=h;r=h;
? while (p1!=h1 && p2!=h2)
? { s=(LinkList *)malloc(sizeof(LinkList));
??? s->data=(p1->data+p2->data+tag)%10000;
?tag=(p1->data+p2->data+tag)/10000;
??? r->next=s;
?r=s;
?p1=p1->next;? p2=p2->next;
? }
? while (p1!=h1)
? { s=(LinkList *)malloc(sizeof(LinkList));
??? s->data=(p1->data+tag)%10000;
?tag=(p1->data+tag)/10000;
??? r->next=s;
?r=s;
?p1=p1->next;
? }
? while (p2!=h2)
? { s=(LinkList *)malloc(sizeof(LinkList));
??? s->data=(p2->data+tag)%10000;
?tag=(p2->data+tag)/10000;
??? r->next=s;
?r=s;
?p2=p2->next;
? }
? r->next=h;
}
void main()
{ LinkList *head,*head1,*head2;
? char str1[100],str2[100];
? cout<<"輸入一個超長正整數a:";
? cin>>str1;
? cout<<"輸入一個超長正整數b:";
? cin>>str2;
非常好我支持^.^
(4) 100%
不好我反對
(0) 0%