zoukankan      html  css  js  c++  java
  • 大整数乘法(POJ2389)

    题目链接:http://poj.org/problem?id=2389

    #include <stdio.h>
    #include <string.h>
    #define Max 100
    
    char a[Max];
    char b[Max];
    int sa[Max];
    int sb[Max];
    
    int ans[Max*Max];
    
    
    int main()
    {
    
        scanf("%s",a);
        getchar();
        scanf("%s",b);
    
        _strrev(a);
        _strrev(b);
    
        int len1=strlen(a);
    
        int len2=strlen(b);
    
        for(int i=0; i<len1; i++)
            sa[i]=a[i]-'0';
        for(int i=0; i<len2; i++)
            sb[i]=b[i]-'0';
    
        for(int i=0; i<len2; i++)
        {
            for(int j=0; j<len1; j++)
            {
                ans[i+j]+=sa[j]*sb[i];
            }
        }
        for(int i=0; i<Max*Max-1; i++)
        {
            if(ans[i]>9)
            {
                ans[i+1]+=ans[i]/10;///整数部分
                ans[i]=ans[i]%10;///余数部分
            }
        }
        int pos=0;
        for(int i=Max*Max-1; i>=0; i--)
            if(ans[i]!=0)
            {
                pos=i;
                break;
            }
    
    
        for(int i=pos; i>=0; i--)
            printf("%d",ans[i]);
    
        puts("");
        return 0;
    }
  • 相关阅读:
    SonarQube
    Gerrit
    Jenkins
    Jenkins
    GitLab
    GitLab
    GitLab
    centos7配置国内yum源
    CentOS7 ping: unknown host www.baidu.com
    VirtualBox下安装CentOS7系统
  • 原文地址:https://www.cnblogs.com/TreeDream/p/5313223.html
Copyright © 2011-2022 走看看