zoukankan      html  css  js  c++  java
  • Codeup_575_特殊乘法

    题目描述

    写个算法,对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
    
    解题关键:一定要记得将每一个字符-'0';我在这里卡了好久。
    AC代码:
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define Max 50 
    using namespace std;
    
    int main(void)
    {
        freopen("in.txt","r",stdin);
        
        char a1[Max],b1[Max];
        while(scanf("%s%s",a1,b1)!=EOF)
        {
            long long sum=0;
            int lena,lenb;
            lena=strlen(a1);
            lenb=strlen(b1);
            for(int i=0;i<lena;i++)
            {
                for(int j=0;j<lenb;j++)
                {
                    sum+=(a1[i]-'0')*(b1[j]-'0');
                }
            }
            
            
            
            printf("%lld
    ",sum);
        }
                
        
        
        fclose(stdin);
        return 0;
    }
  • 相关阅读:
    OAuth
    PHP获取客户端的真实IP
    负载均衡----实现配置篇(Nginx)
    在线时间戳转换
    使用curl进行模拟登录
    定时任务
    Matplotlib使用教程
    CentOS7.X安装PHP
    Python虚拟环境的搭建与使用
    CentOS7.X安装openssl
  • 原文地址:https://www.cnblogs.com/phaLQ/p/10056704.html
Copyright © 2011-2022 走看看