大数相乘
来源:互联网 发布:聚友网络客服电话郑州 编辑:程序博客网 时间:2024/06/01 10:59
#include <iostream>#include <string>using namespace std;class Mul{public: Mul(){} ~Mul() { delete m_ipX; delete m_ipY; delete m_ipOut; } void Input() { string x,y; cin>>x; cin>>y; m_iXLen=x.length(); m_iYLen=y.length(); m_ipX=new int(m_iXLen); m_ipY=new int(m_iYLen); m_ipOut=new int(m_iXLen+m_iYLen); for(int i=0;i<m_iXLen;i++) { m_ipX[m_iXLen-1-i]=x[i]-'0'; } for(int i=0;i<m_iYLen;i++) { m_ipY[m_iYLen-1-i]=y[i]-'0'; } for(int i=0;i<m_iXLen+m_iYLen;i++) { m_ipOut[i]=0; } } void cal() { for(int i=0;i<m_iYLen;i++) { for(int j=0;j<m_iXLen;j++) { m_ipOut[i+j]+=m_ipX[j]*m_ipY[i]; } } for(int i=0;i<m_iYLen+m_iXLen;i++) { if(m_ipOut[i]>=10) { m_ipOut[i+1]+=m_ipOut[i]/10; m_ipOut[i]%=10; } } } void print() { cout<<"X: "; for(int i=0;i<m_iXLen;i++) { cout<<m_ipX[m_iXLen-1-i]; } cout<<endl<<"Y: "; for(int i=0;i<m_iYLen;i++) { cout<<m_ipY[m_iYLen-1-i]; } cout<<endl<<"Out: "; for(int i=m_iXLen+m_iYLen-1;i>=0;i--) { cout<<m_ipOut[i]; } cout<<endl; }private: int* m_ipX; int* m_ipY; int m_iXLen; int m_iYLen; int* m_ipOut;};int main(){ Mul mul; mul.Input(); mul.cal(); mul.print(); return 0;}
0 0
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- 大数相乘
- POJ 3026 Borg Maze (prim+bfs)
- Netty入门到精通一
- Linux -- 统计行数
- putty mtputty 设置utf8编码
- 在mac系统安装Apache Tomcat的详细步骤
- 大数相乘
- 蓝桥杯 格子刷油漆(Java实现)
- KeyEvent
- 通过JavaCompiler动态编译和运行
- 二叉树--链表实现
- 中国近现代史上文笔最好的十位作家
- 从头学习JAVA(五)
- huffman
- RPC,REST,WebService的区别