题目描述:
-
写个算法,对2个小于1000000000的输入,求结果。
特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5
-
输入:
-
两个小于1000000000的数
-
输出:
-
输入可能有多组数据,对于每一组数据,输出Input中的两个数按照题目要求的方法进行运算后得到的结果。
-
样例输入:
-
123 45
-
样例输出:
-
54
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char str1[10], str2[10];
int i, j, sum;
while (scanf("%s %s", str1, str2) != EOF) {
sum = 0;
for (i = 0; i < strlen(str1); i++) {
for (j = 0; j < strlen(str2); j++) {
int a = str1[i] - '0';
int b = str2[j] - '0';
sum += a*b;
}
}
printf("%d\n", sum);
}
return 0;
}