高精度之高精度乘法
来源:互联网 发布:CVI ibevent windows 编辑:程序博客网 时间:2024/05/21 08:03
话说高精度乘法真的没有什么好介绍的,直接上代码:
#include<cstdio>#include<cstdlib>#include<algorithm>#include<cstring>#include<vector>#include<iostream>using namespace std;string a,b;int c[100001],len;void change(string a,string b){ for(int i=b.size()-1;i>=0;i--) { int y=b[i]-'0',bit=b.size()-i-1; for(int j=a.size()-1;j>=0;j--) { len=a.size()-j+bit; int x=a[j]-'0'; c[len]+=x*y; if(c[len] >= 10) { c[len+1]+=c[len]/10; c[len]%=10; } } }}void print(){ int i=1; ++len; while(!c[len]) len--; while( len ) cout<<c[len--];}int main(){ cin>>a>>b; if( a == "0" || b == "0" ) { cout<<'0'; return 0; } else if ( a.size() >= b.size() ) { change ( a , b ); } else change ( b , a ); print (); return 0;}
当然对于高精度乘以低精度的话就没有必要模拟乘法的形式,而可以把低精度数看成一个整体,将它乘到各个位上,再进行进位。
阅读全文
0 0
- 高精度之高精度乘法
- 高精度运算之乘法
- 高精度之乘法
- 高精度之乘法运算
- 高精度之乘法模板
- 高精度算法之乘法
- 高精度-codevs-3117高精度练习之乘法
- 高精度减法,高精度乘法
- 3117 高精度练习之乘法
- 3117 高精度练习之乘法
- p3117 高精度练习之乘法
- 3117 高精度练习之乘法
- 1532: 高精度练习之乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 抽象工厂模式
- 如何在Android用FFmpeg+SDL2.0之同步音频
- 计算机视觉、机器学习相关领域论文和源代码大集合
- Detecting and Recognizing Human-Object Interactions
- 学习vue框架(二)
- 高精度之高精度乘法
- Mask R-CNN
- 人工智能、机器学习与深度学习
- 【TensorFlow】tf.scatter_update()
- C++/MFC-时间与日期
- Python中 sys.argv[]的用法简明解释
- ati2avxx恶意代码手工查杀
- Deep Residual Learning for Image Recognition
- 安卓中沉浸式状态栏实现