• 高精度乘法


    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. }
  • 相关阅读:
    HTTP状态码
    ADB server didn't ACK
    Android 手机震动
    Android 控制闪光灯
    UINavigationItem 设置UIBarButtonItem
    PhotoShop
    在指定时间调用某方法
    被忽视的TWaver功能(1)
    TWaver MONO Design中动画的导出与播放
    TWaver GIS在电信中的使用
  • 原文地址:https://www.cnblogs.com/sysu-zhengwsh/p/3674201.html
Copyright © 2020-2023  润新知