直接上代码了:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<cmath>
  6. #include<queue>
  7. #include<vector>
  8. #include<map>
  9. #include<string>
  10. #include<set>
  11. #define LL long long
  12. #define MAX(a,b) (a>b?a:b)
  13. #define MIN(a,b) (a<b?a:b)
  14.  
  15. using namespace std;
  16.  
  17. char s[50];
  18. int a[50],b[50],c[100];
  19.  
  20. int main()
  21. {
  22. int lena = 0, lenb = 0;
  23. memset(a,0,sizeof(a));
  24. memset(b,0,sizeof(b));
  25. memset(c,0,sizeof(c));
  26.  
  27. gets(s);
  28. for(int i = strlen(s)-1; i>=0; i--)
  29. a[lena++] = s[i]-'0';
  30.  
  31. gets(s);
  32. for(int i = strlen(s)-1; i>=0; i--)
  33. b[lenb++] = s[i] - '0';
  34.  
  35. for(int i = 0; i<50; i++)
  36. {
  37. int last = 0;
  38. for(int j = 0; j<50; j++)
  39. {
  40. c[i+j] += a[i]*b[j];
  41. c[i+j] += last;
  42. last = c[i+j]/10;
  43. c[i+j] = c[i+j]%10;
  44. }
  45. }
  46.  
  47. int t = 99;
  48. while(!c[t]) t--;
  49. while(t>=0) printf("%d",c[t--]);
  50. putchar('\n');
  51.  
  52. return 0;
  53. }

顺便附上高精度加法的函数:

  1. //高精度加法
  2. void highplus(char a[],char b[],char c[])//调用前必须memset
  3. {//将a+b存到c中,直接输出,但c是字符型,要整形则简修改即可
  4. char ch;
  5. int la = strlen(a),lb = strlen(b);
  6. for(int i = 0;i<=(la-1)/2;i++)//将a和b位数倒转,以便逐位相加;同时-‘0’转成整形
  7. {
  8. ch = a[i]-'0';
  9. a[i] = a[la-1-i]-'0';
  10. a[la-1-i] = ch;
  11. }
  12. for(int i = 0;i<=(lb-1)/2;i++)
  13. {
  14. ch = b[i]-'0';
  15. b[i] = b[lb-1-i]-'0';
  16. b[lb-1-i] = ch;
  17. }
  18.  
  19. for(int i = 0;i<100;i++)//这里的100根据调用函数而修改
  20. { //逐位计算,依照加法竖式
  21. c[i] += b[i]+a[i];
  22. c[i+1] += c[i]/10;
  23. c[i] %= 10;
  24. }
  25.  
  26. int i = 99;//若精度不同记得修改
  27. while(!c[i]) i--;//跳过无用的0;
  28. for(int j = 0;j<=i/2;j++)//将c再换成字符型,并再倒叙,使其成为正常数
  29. { //记住要经过中间数,否则中间一个将没有转成字符型,所以用<=(len-1)/2
  30. ch = c[j]+'0';
  31. c[j] = c[i-j]+'0';
  32. c[i-j] = ch;
  33. }
  34. }

POJ2389 —— 高精度乘法的更多相关文章

  1. [vijos P1040] 高精度乘法

    如果这次noip没考好,完全是因为从7月29日之后就没有再写过程序了.说起来,真是一个泪流满面的事实… 那这样一个弱智题练手恢复代码能力,竟然还花了我两个晚上(当然不是两整个晚上…) 第一天TLE了, ...

  2. 【PKU1001】Exponentiation(高精度乘法)

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 145642   Accepted: 35529 ...

  3. hdu 1042 N!(高精度乘法 + 缩进)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目大意:求n!, n 的上限是10000. 解题思路:高精度乘法 , 因为数据量比较大, 所以 ...

  4. hdu 1042 N!(高精度乘法)

    Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!   Input One N in ...

  5. Vijos 1040 高精度乘法

    描述 高精度乘法 输入:两行,每行表示一个非负整数(不超过10000位) 输出:两数的乘积. 样例1 样例输入1 99 101 样例输出1 9999 题解 这道题和之前的Vijos 1010 清帝之惑 ...

  6. 【POJ 1001】Exponentiation (高精度乘法+快速幂)

    BUPT2017 wintertraining(15) #6A 题意 求\(R^n\) ( 0.0 < R < 99.999 )(0 < n <= 25) 题解 将R用字符串读 ...

  7. [leetcode]43. Multiply Strings高精度乘法

    Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and ...

  8. H. GSS and Simple Math Problem 高精度乘法模板

    链接:https://www.nowcoder.com/acm/contest/104/G来源:牛客网 题目描述 Given n positive integers , your task is to ...

  9. 高精度乘法--C++

    高精度乘法--C++ 模仿竖式乘法,在第一步计算的时候将进位保留,第一步计算完再处理进位.(见代码注释) 若要处理正负情况,可在数据输入后加以判断,处理比较简单. 小数计算也可参照该方法,不过对齐方式 ...

随机推荐

  1. 分享Kali Linux 2017年第11周镜像文件

     分享Kali Linux 2017年第11周镜像文件 Kali?Linux官方于3月12日发布2017年的第11周镜像.这次维持了11个镜像文件的规模.默认的Gnome桌面的4个镜像,E17.KDE ...

  2. 济南day4

    啥也不会,做了不对,对了没分.T1 50 + 30 + 0想了想,有思路,写了,半个小时写完,算错复杂度,复杂度最差(n*m),想成了(n+m)被卡没了50分,gg.....T2自己写了个单向并查集, ...

  3. Spring配置项之<aop:aspectj-autoproxy />

    通过配置织入@Aspectj切面 虽然可以通过编程的方式织入切面,但是一般情况下,我们还是使用spring的配置自动完成创建代理织入切面的工作. 通过aop命名空间的<aop:aspectj-a ...

  4. Access自定义函数(人民币大写)

    人民币大写函数:整数不超过13位. Public Function 人民币大写(A) As String Dim aa As String Dim bb As String Dim cc As Str ...

  5. AngularJS的简单表单验证

    代码下载:https://files.cnblogs.com/files/xiandedanteng/angularjsCheckSimpleForm.rar 代码: <!DOCTYPE HTM ...

  6. 关于mysql engine(引擎)的疑问

    http://bbs.chinaunix.net/thread-989698-1-1.html

  7. Android通过JNI实现与C语言的串口通讯操作蓝牙硬件模块

    一直想写一份技术文档,但因为自感能力有限而无从下笔,近期做了个关于Android平台下实现与C语言的通讯来操作蓝牙模块的项目,中间碰到了很多问题,也在网上查了很多资料,在完毕主要功能后.也有一些人在网 ...

  8. 杭电 HDU 1279 验证角谷猜想

    验证角谷猜想 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  9. 函数指针使用演示样例(參考Linux-内核代码)

    本文有xhz1234(徐洪志)编写,转载请注明出处. http://blog.csdn.net/xhz1234/article/details/36635083 作者:徐洪志 近期阅读Linux-内核 ...

  10. caffe2--ubuntu16.04--14.04--install

    Install Welcome to Caffe2! Get started with deep learning today by following the step by step guide ...