首页 > 代码库 > 大数乘法
大数乘法
#include <iostream>#include <cstring>using namespace std;#define MAX 1000000struct Node{ int data; Node* next;};void output(Node* head){ if(!head->next && !head->data) return; output(head->next); cout << head->data;}void Mul(char *a, char *b){ char *ap = a, *bp = b; Node *head = new Node; head->data = http://www.mamicode.com/0; head->next = NULL; Node *p, *q=head, *p1; int temp=0, temp1, bit; while(*bp){ p = q->next; p1 = q; bit = *bp-48; while(*ap || temp){ if(!p){ p = new Node; p->data = http://www.mamicode.com/0; p->next = NULL; p1->next = p; } if(*ap == 0) temp1 = temp; else{ temp1 = p1->data + (*ap-48)*bit + temp; ap++; } p1->data = http://www.mamicode.com/temp1 % 10; temp = temp1 / 10; p1 = p; p = p->next; } ap = a; bp++; q = q->next; } p = head; output(p); cout << endl; while(head){ p = head->next; delete head; head = p; }}int main(){ char a[MAX], b[MAX]; cin.getline(a, MAX, ‘\n‘); cin.getline(b, MAX, ‘\n‘); Mul(strrev(a), strrev(b)); return 0;}
大数乘法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。