///Big data multiplication, concrete algorithm idea see C
#define_crt_secure_no_warnings//vs2013 Remove Security check#include<stdlib.h>#include<string.h>#include<iostream>using namespacestd;classbig_data{ Public: voidinit_string () {cout<<"str1 ="; CIN>>str1; cout<<Endl; cout<<"str2 ="; CIN>>str2; cout<<Endl; } Char*Big_data_multi () {intLENGTH_STR1 =strlen (STR1); intLENGTH_STR2 =strlen (STR2); int*PSTR3 = (int*)malloc(sizeof(int) * (length_str1+length_str2)); memset (PSTR3,0,sizeof(int) * (LENGTH_STR1+LENGTH_STR2));//Be sure to initialize, otherwise garbled for(inti =0; i < LENGTH_STR2; i++)//Cyclic multiplicative addition { for(intj =0; J < Length_str1; J + +) {Pstr3[i+ j +1] + = (str1[j)-'0') * (Str2[i]-'0'); } } for(inti = length_str1 + LENGTH_STR2-1; I >=0; i--) { if(Pstr3[i] >=Ten) {Pstr3[i-1] + = Pstr3[i]/Ten; Pstr3[i]= pstr3[i]%Ten; } } inti =0; while(Pstr3[i] = =0) {i++; } Char*PSTR4 = (Char*)malloc(sizeof(Char) * (LENGTH_STR1 + length_str2 +1)); intj =0; for(; J < length_str1+length_str2 && i < length_str1+length_str2; j++,i++) {Pstr4[j]= Pstr3[i] +'0'; } Pstr4[j]=' /'; returnPSTR4; }Private: Charstr1[ -]; Charstr2[ -];};intMain () {Big_data bigdata1; while(1) {cout<<Endl; Bigdata1.init_string (); cout<<"The result of multiplying is:"<< Bigdata1.big_data_multi () <<Endl; } System ("Pause");}
Multiplication of Big Data