高精度乘法
来源:互联网 发布:伤感好听的网络歌曲 编辑:程序博客网 时间:2024/06/03 03:37
高精度乘法
新定义‘*’
#include<cstdio>
#include<cstring>
using
namespace
std;
struct
sd {
int
len,d[300];
//sd(){memset(d,0,sizeof(d));}
sd operator * (
const
sd &x)
const
{
sd c;
for
(
int
i=0;i<300;i++) c.d[i]=0;
for
(
int
i=0;i<len;i++)
for
(
int
j=0;j<x.len;j++)
{
c.d[i+j]+=d[i]*x.d[j];
c.d[i+j+1]+=c.d[i+j]/10;
c.d[i+j]%=10;
}
for
(
int
i=0;i<=len-1+x.len-1;i++)
{
c.d[i+1]+=c.d[i]/10;
c.d[i]%=10;
}
if
(c.d[len+x.len-1]>0) c.len=len+x.len;
else
c.len=len+x.len-1;
return
c;
}
};
void
ready(sd &x)
{
char
st[300];
scanf
(
"%s"
,st);
x.len=
strlen
(st);
int
j=0;
for
(
int
i=x.len-1;i>=0;i--)
{x.d[j]=st[i]-48;j++;}
}
int
main()
{
sd x1,x2,s;ready(x1);ready(x2);
s=x1*x2;
for
(
int
i=s.len-1;i>=0;i--)
printf
(
"%d"
,s.d[i]);
printf
(
"\n"
);
return
0;
}
阅读全文
0 0
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- 高精度乘法
- centos 下的zabbix以及常见问题
- spring aop部分
- iOS开发 HomeKit Accessory Simulator
- 远程连接树莓派,ssh,putty,vnc,xrdp
- Linux下安装Matlab2014及破解
- 高精度乘法
- python里把dir函数当作查看成员输出
- 《机器学习实战》代码片段学习4 Logistic回归
- 某某复试机试题--------删除代码中的注释
- 我的第一篇博客
- ElasticSearch常见操作
- 大数据与深度学习区别
- c++下实用的工具stringstream
- 唐巧总结的40个国人iOS技术博客