特殊乘法

题目描述

写个算法,对2个小于1000000000的输入,求结果。特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5

输入

 两个小于1000000000的数

输出

 输入可能有多组数据,对于每一组数据,输出Input中的两个数按照题目要求的方法进行运算后得到的结果。

样例输入

24 65
42 66666
3 67

样例输出

66
180
39
#include<cstdio>
const int maxn = 100010;
int main() {
	char a[maxn], b[maxn];
	while (scanf("%s %s", a, b) != EOF) {
		int sum = 0;
		for(int i=0;a[i]!='\0';i++)        //for语句要会灵活运用,这样就不用strlen了。。。
			for(int j=0;b[j]!='\0';j++)
				sum += (a[i] - '0')*(b[j] - '0');
			
		printf("%d\n", sum);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/joah_ge/article/details/80515757