zoukankan      html  css  js  c++  java
  • 【慢慢学算法】:特殊乘法

       题目描述:   

    写个算法,对2个小于1000000000的输入,求结果。

    特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5

    输入:

     两个小于1000000000的数

    输出:

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

    样例输入:
    123 45
    样例输出:
    54
    代码:
    #include<stdio.h>
    int main()
    {
        long long x, y, temp1, temp2, sum;
        int index1, index2;
        char a[11],b[11];
        while(scanf("%lld%lld",&x,&y) != EOF)
        {
    	temp1 = x;
    	temp2 = y;
    	index1 = 0;
    	index2 = 0;
    	sum = 0;
    	while(temp1 != 0)
    	{ a[index1++] = temp1%10 ; temp1 = temp1/10;}
    	while(temp2 != 0)
    	{ b[index2++] = temp2%10 ; temp2 = temp2/10;}
    	for(int i = 0; i < index1; i++)
    	    for(int j = 0; j < index2; j++)
    		sum += (int)a[i]*(int)b[j];
    	printf("%lld\n",sum);
        }
        return 0;
    }
    

      

  • 相关阅读:
    Python学习资料
    异常
    I/O
    Python3+迭代器与生成器
    python标准数据类型
    人工智能、机器学习和深度学习
    原地排序和复制排序
    序列化和Json
    登陆加密小程序
    hashlib模块加密用法
  • 原文地址:https://www.cnblogs.com/VortexPiggy/p/2514804.html
Copyright © 2011-2022 走看看