【算法笔记】特殊的乘法
http://codeup.hustoj.com/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
*********************************************************************************************************
/*思路:没啥思路,不想用拆分的话,就直接写成数组形式,然后参考上一篇A+B的char型数字转换成int型。
或者选择拆分整数的话,用取余,取整,存到整型数组里,然后再计算,可以参考如下答案(来自网络)(60条消息) 题目1083:特殊乘法[数位拆解]_ivolcano的博客-CSDN博客
*/
#include<stdio.h>
#include<string.h>
#define maxn 100010
int main(){
char A[maxn];
char B[maxn];
while(scanf("%s %s",A,B)!=EOF){
int a=strlen(A);
int b=strlen(B);
int sum=0;
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
sum=sum+(A[i]-'0')*(B[j]-'0');
}
}
printf("%d\n",sum);
}
return 0;
}