高精度
来源:互联网 发布:diy软件 编辑:程序博客网 时间:2024/04/29 20: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;
int
k=len>x.len?len:x.len;
for
(
int
i=0;i<k;i++)
if
(i<len && i<x.len)
c.d[i]=d[i]+x.d[i];
else
if
(i>=len && i<x.len)
c.d[i]=x.d[i];
else
c.d[i]=d[i];
c.d[k]=0;
for
(
int
i=0;i<k;i++)
{c.d[i+1]+=c.d[i]/10;c.d[i]%=10;}
if
(c.d[k]>0) c.len=k+1;
else
c.len=k;
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
- 高精度
- 高精度
- 高精度
- 高精度。。
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 面试题
- Xmind在项目管理中运用
- windows mysql 32位 安装
- LintCode:M-大数相乘
- SpringMvc之数据校验
- 高精度
- 使用Raspi-config配置工具来设置树莓派
- MSSQL如何在原有数据库上新建测试数据库?
- http传输方法
- 码云zheng项目介绍
- android效果之跑马灯
- 架构设计三部曲之如何评审架构设计说明书(转)
- 操作给定的二叉树,将其变换为源二叉树的镜像。
- asp.net之GridView+UpdatePanel异步刷新