题目大意:求两个数的成积

解题思路:分步解决,一个个相乘再相加

#include<cstdio>
#include<cstring>

void add(char *sum, char * num2,int len) {
	int i;
	for( i = 0 ; i < len; i++) {
		int num = sum[i] + num2[i] - '0';
		sum[i] = num % 10;
		if(num > 9)
			sum[i+1] = sum[i+1] + 1;
	}
}
int main() {
	char num1[1000];
	char num2[1000];
	while( gets(num1)) {
		gets(num2);
		int len1 = strlen(num1);
		int len2 = strlen(num2);

		char temp[1000];
		char sum[2000] = {0};
		int j , l;
		for(int i = len1 - 1, k = 0; i >= 0; i--, k++)  {
			int mark = 0;
			for( j = len2 - 1, l = k; j >= 0; j--,l++)  {
				int num =( num1[i] - '0') * (num2[j] - '0') + mark;
				mark = num / 10;
				num = num % 10;
				temp[l] = num + '0';
			}  
			if(mark > 0) {
				temp[l] = mark + '0';
				l++;
			}
			add(sum,temp,l);
			memset(temp,'0',sizeof(temp));
		}

		int len3 = 1999;
		if(num1[0] == '0' && len1 == 1 || num2[0] == '0' && len2 == 1)
			printf("0");
		else {
			for(;;len3--)
				if(sum[len3] != 0)
					break;
			for(int i = len3; i >= 0; i--) 
				printf("%d",sum[i]);
		}
		printf("\n");
	}	
	return 0;
}