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. }
  • 相关阅读:
    Intellij IDEA13 创建多模块Maven项目
    oracle锁
    oracle rac负载均衡
    awk命令
    政务外网、政务专网、政务内网和互联网
    图片切换实现选中-未选中效果
    生成带logo 的二维码
    控制input为number时样式
    移动端适配的解决方法?
    input-checkbox选中及非选中样式设置
  • 原文地址:https://www.cnblogs.com/sysu-zhengwsh/p/3674201.html
Copyright © 2011-2022 走看看