大整数乘法
来源:互联网 发布:录音音乐合成软件 编辑:程序博客网 时间:2024/06/03 18:30
6:大整数乘法
- 查看
- 提交
- 统计
- 提问
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
求两个不超过200位的非负整数的积。
- 输入
- 有两行,每行是一个不超过200位的非负整数,没有多余的前导0。
- 输出
- 一行,即相乘后的结果。结果里不能有多余的前导0,即如果结果是342,那么就不能输出为0342。
- 样例输入
1234567890098765432100
- 样例输出
1219326311126352690000
- 提示
- 30%的数据,输入的两个整数不超过8位。
#include<iostream>#include<cmath>#include<cstring>#include<algorithm>#include<iomanip>#include<queue>#include<stack>#include<vector>#include<set>#include<map>using namespace std;string s1,s2;int a[205]={0};int b[205]={0};int c[40005]={0};int main(){cin>>s1>>s2;a[0]=s1.length();b[0]=s2.length();for(int i=1;i<=a[0];++i){a[i]=s1[a[0]-i]-'0';}for(int i=1;i<=b[0];++i) {b[i]=s2[b[0]-i]-'0';}c[0]=a[0]+b[0]-1;for(int i=1;i<=a[0];++i){for(int j=1;j<=b[0];++j){c[i+j-1]+=a[i]*b[j];}}for(int i=1;i<=c[0];++i){if(c[i]>=10){c[i+1]+=c[i]/10;c[i]=c[i]%10;}}if(c[c[0]+1]>0)c[0]++; while(c[c[0]]>=10){c[c[0]+1]+=c[c[0]]/10;c[c[0]]=c[c[0]]%10;c[0]++;}for(int i=c[0];i>=1;--i){cout<<c[i];}cout<<endl;return 0;}
阅读全文
0 0
- 大整数乘法
- C++大整数乘法
- 大整数FFT乘法
- 大整数乘法
- 大整数乘法
- 大整数乘法
- 大整数乘法
- 大整数乘法。。。。。
- 大整数乘法
- 大整数乘法
- // //大整数乘法
- 大整数乘法
- 大整数乘法算法
- 【算法】 大整数乘法
- 大整数乘法
- 大整数乘法
- 大整数乘法。
- 大整数乘法
- 笔记--xml简介
- Linux 学习笔记(一)
- 服务器中判断客户端socket断开连接的方法
- PHP使用Redis存储
- POJ1035-Spell checker(字符串,模拟)
- 大整数乘法
- Zookeeper学习笔记 --- Python操作zookeeper
- 小菜鸟对并发编程的理解
- 图形学(1)概论及一些基础知识
- iOS开发中时间戳和时间的相互转换
- commom fileupload结构
- JdKAPI掌握
- UVa156 map
- GDAL RasterIO使用说明