43. Multiply Strings
2016-03-08 21:06
495 查看
<span style="font-size:18px;">string multiply(string num1, string num2) { if (num1 == "0" || num2 == "0") return "0"; int sa = num1.size(); int sb = num2.size(); vector<int> temp(sa + sb, 0); for (int i = sa - 1; i >= 0; i--) { int a = num1[i] - '0'; for (int j = sb - 1; j >= 0; j--) { int b = num2[j] - '0'; int product = a*b; int carry = (temp[j + i + 1] + product) / 10; temp[j + i + 1] = (temp[j + i + 1]+product) % 10; int x = 0; while (carry) { int p = temp[j + i - x] + carry; temp[j + i - x] = p % 10; carry = p / 10; x++; } } } while (temp[0] == 0) temp.erase(temp.begin()); string res; for (int i = 0; i < temp.size(); i++) { res += to_string(temp[i]); } return res; }</span>
相关文章推荐
- Ant入门
- 不同渲染路径 4000 下Pass执行规则总结
- BestCoder Round #74 (div.2)
- (完全背包) hdu 1114 Piggy-Bank
- MySQL 忘记ROOT密码修复策略
- 排序算法之导论
- 网络七层 以及iOS开发中的get请求 post请求
- 学习进度条
- 数组求和
- grep文本过滤 / 正则表达式
- mybatis防止sql注入
- Android---SharedPreferences 记住用户名和密码
- virtualbox kali linux 安装小米随身wifi
- eclipse安装ADT后不显示插件的小问题
- java/android基础总结1
- Contains Duplicate II-副本包含
- strcpy()
- 对AnyChat录屏解决方案的调研报告
- 心理学学习(一) 心理学研究的基本方法
- EVC编程点滴-GIF动画显示类