大整数乘法CPP
来源:互联网 发布:mysql查询子语句 编辑:程序博客网 时间:2024/06/03 15:03
描述
求两个不超过200位的非负整数的积。
输入
有两行,每行是一个不超过200位的非负整数,没有多余的前导0。
输出
一行,即相乘后的结果。结果里不能有多余的前导0,即如果结果是342,那么就不能输出为0342。
#include<iostream>#include<algorithm>#include<string>#include<string.h>using namespace std;const int maxn = 205;int main(){string str1, str2;int a[maxn];int b[maxn];int len1, len2, i, j;cin >> str1 >> str2;len1 = str1.length();len2 = str2.length();for (i = 0, j = len1 - 1; i < len1; i++, j--)a[i] = str1[j] - '0';for (i = 0, j = len2 - 1; i < len2; i++, j--)b[i] = str2[j] - '0';int c[2*maxn];memset(c, 0, sizeof(c));for (i = 0; i < len1; i++){for (j = 0; j < len2; j++){c[i + j] += a[i] * b[j];if (c[i + j] >= 10){c[i + j + 1] += c[i + j] / 10;c[i + j] %= 10;}}}i = len1 + len2 - 1;if (c[i] == 0)i--;for (i; i >= 0; i--)cout << c[i];cout << endl;return 0;}
1 0
- 大整数乘法CPP
- 大整数乘法
- C++大整数乘法
- 大整数FFT乘法
- 大整数乘法
- 大整数乘法
- 大整数乘法
- 大整数乘法
- 大整数乘法。。。。。
- 大整数乘法
- 大整数乘法
- // //大整数乘法
- 大整数乘法
- 大整数乘法算法
- 【算法】 大整数乘法
- 大整数乘法
- 大整数乘法
- 大整数乘法。
- IOS百度地图屏幕坐标与经纬度坐标的转换
- Pattern Matching
- 01作业
- 使用angularjs1.x构建前台开发框架(二)——require的使用
- iOS开发-事件传递与响应者链中的hitTest方法和pointInside方法
- 大整数乘法CPP
- 周详:重价救赎 · 《天下无贼》电影与王宝强离婚风波
- C++ 取代switch的三种方法
- 【操作系统】磁盘调度
- 周详:师生之道 ·《西游记》与德云社师徒大战 ︱ 中法评
- java--MVC框架结构
- 欢迎使用CSDN-markdown编辑器
- 遥远的救世主:电视剧《天道》
- mjpg-streamer工作流程