zoukankan      html  css  js  c++  java
  • 大数乘法 zju 1217

    大数乘
    Time Limit:5000MS  Memory Limit:32768K

    Description:

    给定一些大数,请计算其积。

    Input:

    输入数据中含有一些整数对(对数≤1000),若某对整数(整数位数≤200)的值为0 0,则表示输入结束。

    Output:

    每对整数对应一个乘法计算结果,输出该结果,每个结果输出完后应回车。

    Sample Input:

    2 3
    12 34
    0 0
    

    Sample Output:

    6
    408
    

     1 /* 功能Function Description:     大数相乘
     2    开发环境Environment:          DEV C++ 4.9.9.1
     3    技术特点Technique:
     4    版本Version:
     5    作者Author:                   可笑痴狂
     6    日期Date:                     20120725
     7    备注Notes:
     8 */
     9 #include<stdio.h>
    10 #include<string.h>
    11 #define MAX 210
    12 
    13 int main()
    14 {
    15     char s1[MAX],s2[MAX];
    16     int i,j,len1,len2;
    17     int a[MAX],b[MAX],res[MAX*2];
    18     while(scanf("%s%s",s1,s2))
    19     {
    20         memset(res,0,sizeof(res));
    21         if(strcmp(s1,"0")==0&&strcmp(s2,"0")==0)
    22             break;
    23         len1=strlen(s1);
    24         len2=strlen(s2);
    25         for(i=len1-1,j=0;i>=0;--i)
    26             a[j++]=s1[i]-'0';
    27         for(i=len2-1,j=0;i>=0;--i)
    28             b[j++]=s2[i]-'0';
    29         for(i=0;i<len2;++i)    
    30             for(j=0;j<len1;++j)
    31                 res[i+j]+=b[i]*a[j];    //解题关键
    32         for(i=0;i<MAX*2-1;++i)
    33         {
    34             if(res[i]>=10)
    35             {
    36                 res[i+1]+=res[i]/10;
    37                 res[i]%=10;
    38             }
    39         }
    40         while(i>=0&&res[i]==0)
    41             --i;
    42         if(i>=0)
    43         {
    44             for(;i>=0;--i)
    45                 printf("%d",res[i]);
    46             printf("\n");
    47         }
    48         else
    49             printf("0\n");
    50     }
    51     return 0;
    52 }
    功不成,身已退
  • 相关阅读:
    Centos7
    appium+python常见报错(appium方面)
    python标准库之datetime
    python异常捕获
    python写入文件和读取文件
    python标准库之collections
    python导入类
    python3+robotframework+pycharm安装运行
    python 继承/父类和子类的关系
    python_类
  • 原文地址:https://www.cnblogs.com/dongsheng/p/2608839.html
Copyright © 2011-2022 走看看