zoukankan      html  css  js  c++  java
  • 高精度乘法

    You'll be given two intergers. The number of the digits of each is from 1 to 200, inclusive.

        And what you need to do is to culcalate the product of the two intergers.

        The number of the digits of the product won't be more than 400.



    Input format:

        Two lines in total.

        The first line is an interger a(0 <= a < 10200), and the second line is an interger b(0 <= b < 10200).

    Output format:

        Only one line, which is the product of a and b.



    Sample input:

    12

    2

    Sample output:

    24

    1. #include<stdio.h>
    2. #include<string.h>
    3.  
    4. int multiplication(char*a,char*b,int*c);
    5. int main(){
    6. int c[400+10], i;
    7. int k;
    8. char a[200+10]={0};
    9. char b[200+10]={0};
    10. memset(c,0,sizeof(c));
    11. gets(a);
    12. gets(b);
    13. if((a[0]=='0')||(b[0]=='0')){
    14. printf("0 ");
    15. }else{
    16. k = multiplication(a, b, c);
    17. for(i = k; i >=1; i--) printf("%d", c[i]);
    18. printf(" ");
    19. }
    20. return0;
    21. }
    22. int multiplication(char*a,char*b,int*c){
    23. int i, j, m, tem, k =405, la, lb;
    24. la = strlen(a);
    25. lb = strlen(b);
    26. for(i = lb -1; i >=0; i--){
    27. for(j = la -1, m =0; j >=0; j--){
    28. tem = c[(lb-i)+(la-j)-1];
    29. c[(lb-i)+(la-j)-1]=
    30. ((a[j]-'0')*(b[i]-'0')+ m + c[(lb - i)+(la - j)-1])%10;
    31. m =((a[j]-'0')*(b[i]-'0')+ m + tem)/10;
    32. }
    33. c[(lb-i)+(la-j)-1]= m;
    34. }
    35. while(!c[k]) k--;
    36. return k;
    37. }
  • 相关阅读:
    nano编辑器__vi常用命令
    pyCharm最新2018激活方式(记录)
    一、centos7.4安装docker
    C#备份及还原数据库的实现
    System.Drawing.image 与ImageSource 互转
    Socket 异步通信
    图片与base64的互转
    程序中编写log日志
    SQLHelper
    Cond
  • 原文地址:https://www.cnblogs.com/sysu-zhengwsh/p/3674201.html
Copyright © 2011-2022 走看看