1、题目描述

2、问题分析

按照手算乘法的过程进行计算,首先计算乘法,然后计算加法。

3、代码

 string multiply(string num1, string num2) {
string small ;
string big;
if( num1.size() < num2.size() ){
small = num1;
big = num2;
}else if( num2.size() < num1.size() ){
small = num2;
big = num1;
}else{
small = num1;
big = num2;
} int n = small.size() ;
vector<string> re; string::reverse_iterator it_s = small.rbegin() ;
while( it_s != small.rend() ){
string s;
int up = ;
string::reverse_iterator it_b = big.rbegin() ;
while( it_b != big.rend() ){
int m = (*it_s - '') * (*it_b - '') + up;
if( m < ){
s = std::to_string(m) + s;
up = ;
}else{
s = std::to_string( m% ) + s;
up = m/;
}
++it_b;
}
if( up != ){
s = std::to_string( up ) + s;
}
re.push_back( s );
++it_s;
} string zero;
for( vector<string>::iterator it = re.begin() ; it != re.end() ; it++ ){
*it += zero;
zero += "";
} string result = "" ;
for( int i = ; i < re.size() ; i++ ){
result = binaryAdd( result , re[i] );
} int q = ;
for( string::iterator it = result.begin() ; it != result.end() ; ++it ){
q += (*it - '');
}
if( q == )
result = "";
return result; } string binaryAdd( string s1 , string s2 ){
string s;
string::reverse_iterator it1 = s1.rbegin();
string::reverse_iterator it2 = s2.rbegin();
int up = ;
while( it1 != s1.rend() && it2 != s2.rend() ){
int a = (*it1 - '') + (*it2 - '') + up;
if( a < ){
s = std::to_string(a) + s;
up = ;
}else{
s = std::to_string( a - ) + s;
up = ;
}
++it1 ;
++it2 ;
} while( it1 != s1.rend() ){
if( *it1 - '' + up < ){
s = std::to_string( *it1 - '' + up ) + s;
up = ;
}else{
s = std::to_string( *it1 - '' + up - ) + s;
up = ;
}
++it1;
} while( it2 != s2.rend() ){
if( *it2 - '' + up < ){
s = std::to_string( *it2 - '' + up ) + s;
up = ;
}else{
s = std::to_string( *it2 - '' + up - ) + s;
up = ;
}
++it2;
} if( up == ){
s = std::to_string() + s;
}
return s;
}

最新文章

  1. bzoj1080
  2. cheap gucci bags for women finish fashion jewellery has to move
  3. safari浏览器添加书签的方法
  4. BZOJ4004: [JLOI2015]装备购买
  5. 简单3d RPG游戏 之 005 选择敌人
  6. 点击推送消息跳转处理(iOS)
  7. .net 网站应对压力的一些方案总结
  8. 使用Mybatis-Generator自己主动生成Dao、Model、Mapping相关文件
  9. NET快速信息化系统开发框架 V3.2 -&gt; “用户管理”主界面使用多表头展示、增加打印功能
  10. PWM_MOTOR_B
  11. 查看PostgreSQL正在执行的SQL
  12. npm install xxx --save-dev 与npm install xxx --save 的区别
  13. return的一种用法:如果当前判断为true则跳出这个方法。
  14. python全栈 函数名 闭包及迭代器
  15. Beta 冲刺 四
  16. QT编译错误: multiple definition of `qMain(int, char**)&#39;
  17. 怎样设置linux中Tab键的宽度(可永久设置)
  18. mac 操作idea快捷键
  19. Mysql常用函数汇总-经典实用
  20. js使用s:property标签接收json格式数据

热门文章

  1. css设置:图片文字等不能被选择
  2. Java学习之路(九):Map集合
  3. web前端之css快速入门
  4. 前端通信:ajax设计方案(三)--- 集成ajax上传技术
  5. rpm使用方法
  6. 用ruby调用执行shell命令
  7. input属性type为file打开文件资源管理器时,如何限制多次选取或只能一次选取的行为
  8. 回溯法求解n皇后和迷宫问题
  9. springboots 配置文件
  10. Angular的第一个组件