大數
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
const int OneNode = 1000000; //一位里不能超過OneNode
const int NodeLen = 6; //一位儲存NodeLen位,和OneNode必須同時更改,輸出部分格式必須跟隨這里!!!
const int NumMax = 50; //儲存位數限制,真實位數為NumMax*6
struct BigNum


{
unsigned num[NumMax] ;//高位 對 下標大位
unsigned numlen ;

void set(unsigned sm=0)
{ num[0] = sm ; numlen = 1; }//sm<OneNode
void set(char *string , int strlen)

{
numlen = (strlen-1) / NodeLen + 1 ;
memset (num , 0 , sizeof(unsigned)*numlen );
int temp , i ;
for( i=strlen-1 ; i>=0 ; i-- )

{
temp = i / NodeLen ;
num[temp] = num[temp]*10 + string[strlen-1-i]-'0' ;
}
}
void print()

{
printf("%d",num[numlen-1]);
int i = numlen-1;
while( i )

{
i--;
printf("%06d",num[i]);
}
printf("\n");
}
};

void Mul(BigNum &a,BigNum &b,BigNum &c) // a*b ->c


{
unsigned carry = 0 , lenmax = a.numlen+b.numlen-1 ,i,j ;
unsigned __int64 temp ;
c.numlen = lenmax;
for ( i=0 ; i<lenmax ; i++ )

{
temp = carry ;
for ( j=0 ; j<a.numlen ; j++ )

{
if ( i<j )
break;
if ( i-j >= b.numlen )

{
j = i-b.numlen ;
continue;
}
temp += (unsigned __int64)a.num[j] * b.num[i-j] ;
}
carry = temp / OneNode ;
c.num[i] = temp % OneNode ;
}
if(carry)

{
c.num[i] = carry ;
c.numlen ++;
}
}

BigNum a, b, c;
char ta[41], tb[41];

int main()


{

while(scanf("%s%s", ta, tb) != EOF)

{
a.set(ta, strlen(ta));
b.set(tb, strlen(tb));

Mul(a, b, c);
c.print();
}
return 0;
}
運算










































































































