Untitled
unknown
plain_text
2 years ago
1.7 kB
1
Indexable
Never
#include <iostream> #include <string> #include <string> #include <cstdlib> #include "function.h" using namespace std; INT INT::operator*(INT b){ INT new_int; int a_len=this->len,b_len=b.len; int len; if(a_len>b_len) len=a_len+1; else len=b_len+1; new_int.len=0; new_int.data[0]='0'; int overflow=0; int a_idx=a_len-1,b_idx=b_len-1; int count=0; int a_num=0,b_num=0; int n=0; for(int i=a_len-1;i>=0;i--){ INT a_int; b_idx=b_len-1; a_num=(int)(this->data[a_idx]-'0'); overflow=0; for(int j=b_len-1;j>=0;j--){ if(b_idx<0) b_num=0; else b_num=(int)(b.data[b_idx]-'0'); //cout<< a_num <<"*"<<b_num<<"="; count=a_num*b_num+overflow; if(count>=10){ overflow=count/10; count=count%10; } else{ overflow=0; count=count%10; } a_int.data[j]=(char)(count+'0'); //cout<< a_int.data[j] <<" "; b_idx--; } /*if(overflow>0){ for(int k=b_len-1;k>=0;k--){ a_int.data[k+1]=a_int.data[k]; } a_int.data[0]=(char)(overflow+'0'); }*/ //cout<< "\n"; count=0; for(int k=1;k<=n;k++){ a_int.data[b_len-1+k]='0'; //cout<< a_int <<"\n"; } a_int.len=b_len+n+1; //new_int.len=b_len+n; new_int=a_int + new_int; //cout<< new_int <<"\n"; a_idx--; n++; } new_int.len=a_len+b_len; return new_int; }