10106 Product

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int mutil(char * x, char * y , char * z)
{
	char * px = x;
	char * py = y;
	int carry =0 , temp;
	if(strcmp(x,"0") == 0 || strcmp(y,"0") == 0)
	{
		z[0] = 0;
		return 1;
	}
	int i,j;
	for(i = 0 ; *(i+px) ; ++i)
	{
		carry = 0;
		for(j = 0 ; *(py+j) ; ++j)
		{
			temp = (*(px+i)-'0')*(*(py+j)-'0')+carry+z[i+j];

			carry = temp/10;
			temp = temp%10;
			z[i+j] = temp;
		}
		if(carry!= 0)
		{
			z[i+j] = carry;
		}
	}
	if(carry != 0)
	{
		return i+j;
	}
	return i+j-1;
}

int main()
{
	char buff1[1000],buff2[1000];
	char result[100001] = {0};
	int len1,len2;
	int result_len = 0;
		while(	cin>>buff1>>buff2)
		{
				len1 = strlen(buff1);
				len2 = strlen(buff2);
				result_len = 0;

				reverse(buff1,len1+buff1);
				reverse(buff2,buff2+len2);
				fill(result,result+sizeof(result),0);
				result_len = mutil(buff1,buff2,result);

				result[result_len] = 0;
				reverse(result,result+result_len);
				transform(result,result+result_len,result,bind2nd(plus<int>(),48));
				cout<<result<<endl;
		}
	return 0;
}
原文地址:https://www.cnblogs.com/UnGeek/p/2566394.html