九度 Online Judge 算法 刷题 题目1083:特殊乘法

时间:2022-01-21 12:21:00

题目1083:特殊乘法

题目描述:
写个算法,对2个小于1000000000的输入,求结果。
特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5
输入:
两个小于1000000000的数
输出:
输入可能有多组数据,对于每一组数据,输出Input中的两个数按照题目要求的方法进行运算后得到的结果。
样例输入:
123 45
样例输出:
54
来源:
2010年清华大学计算机研究生机试真题

code

c语言实现

#include<stdio.h>
 
int main() {
     int a,b;
    int bb;
    int temp;
    while (scanf("%d %d",&a,&b) != EOF) {
        if (a>1000000000 || b>1000000000)
            continue;
        else {
            temp = 0;
            if (a ==0)
                printf ("0\n");
            while (a != 0) {
                bb = b;
                while (bb != 0) {
                    temp += (a%10) * (bb%10);
                    bb = bb/10;
                }
                a = a/10;
                if ( a == 0)
                    printf("%d\n",temp);   
            }
        }  
    }
    return 0;
}
/**************************************************************
    Problem: 1083
    User: langzimaizan
    Language: C
    Result: Accepted
    Time:0 ms
    Memory:912 kb
****************************************************************/