Codeup墓地 Contest100000575 问题 C: 特殊乘法

题目描述

写个算法,对2个小于1000000000的输入,求结果。特殊乘法举例:123 * 45 = 14 +15 +24 +25 +34+35

输入

两个小于1000000000的数

输出

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

样例输入

24 65
42 66666
3 67

样例输出

66
180
39

代码:

#include<cstdio>
int main(){
	int a,b;
	char str_a[11],str_b[11]; 
	while(scanf("%d%d",&a,&b)!=EOF){
		int c=0;
		sprintf(str_a,"%d",a),sprintf(str_b,"%d",b);
		for(int i=0;str_a[i]!='\0';++i){
			for(int j=0;str_b[j]!='\0';++j){
				c+=(str_a[i]-'0')*(str_b[j]-'0');
			}
		}
		printf("%d\n",c);
	}
	return 0;
} 

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_37205425/article/details/85061262