codeup—特殊乘法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m0_37345402/article/details/81839221

题目链接:http://www.codeup.cn/problem.php?cid=100000575&pid=2

题目描述

写个算法,对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<stdio.h>
#include<string.h>
int main(){ 
	char str1[12],str2[12];
	while(scanf("%s%s",str1,str2)!=EOF){
		int len1=strlen(str1);
		int len2=strlen(str2);
		int mul=0;
		for(int i=0;i<len1;i++){
			for(int j=0;j<len2;j++){
				mul+=(str1[i]-'0')*(str2[j]-'0');
			}
		}
		printf("%d\n",mul);
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_37345402/article/details/81839221