#include <iostream> #include <fstream> #include <cmath> #include <string> #include <iomanip> #include <algorithm> #include <stdio.h> //using namespace std; std::ifstream cin("in.txt"); std::ofstream cout("out.txt"); const int LENGHT = 100; /*************************************** **功能是大数乘法 **技巧:边乘边计算 ** tmp = c[i+j]+a[i]*b[j]+nCarry; ** 1 2 3 ** X 1 2 ** --------- ** 2 4 6 ** 1 2 3 ** --------- ***************************************/ void big_multiply(int* a,int* b) { int c[LENGHT] ={0}; int nCarry = 0; int tmp = 0; for (int i = 0; i<LENGHT; i++) { nCarry = 0; for (int j = 0; j<LENGHT-i; j++) { tmp = c[i+j]+a[i]*b[j]+nCarry; c[i+j] = tmp%10; nCarry = tmp/10; } } std::memcpy(a,c,sizeof(c)); } int main(int argc, char* argv[]) { std::string a,b; while (cin>>a>>b) { //cout<<big_point_plus(a,b)<<std::endl; int aInt[LENGHT]={0}; int bInt[LENGHT]={0}; for (int i = a.length()-1,j=0;i>=0;i--) { aInt[j++] = a[i]-'0'; } for (int i = b.length()-1,j=0;i>=0;i--) { bInt[j++] = b[i]-'0'; } big_multiply(aInt,bInt); bool nStartOutPut = false; for (int i = LENGHT-1;i>=0;i--) { if (nStartOutPut) { cout<<aInt[i]; } else if(aInt[i]) { cout<<aInt[i]; nStartOutPut = true; } } cout<<"/n"; } return 0; } 大数乘法