高精度加法
来源:互联网 发布:监控器找不到网络主机 编辑:程序博客网 时间:2024/06/05 17:06
原 题:
输入两个正整数,求它们的和。
算法分析:
竖式方法,分别用一个数组存储补加数,一个数组存储加数,一个数组存储结果。
代 码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[301],b[301],c[301];
int main()
{string s,js;
int lena,lenb,lenc,x;
cin>>s;
cin>>js;
lena=s.length();
lenb=js.length();
for (int i=1;i<=lena;++i)
a[i]=s[lena-i]-'0';
for (int j=1;j<=lenb;++j)
b[j]=js[lenb-j]-'0';
lenc=1;
x=0;
while(lenc<=lena||lenc<=lenb)
{c[lenc]=a[lenc]+b[lenc]+x;
x=c[lenc]/10;
c[lenc]=c[lenc]%10;
lenc++;
}
c[lenc]=x;
if(c[lenc]==0)lenc--;
for (int j=lenc;j>=1;j--)
cout<<c[j];
return 0;
}
1 0
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度 加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- 高精度加法
- Node和es6的兼容性
- 【Hadoop & Hbase】大数据存储系统编程_读出写入
- sublime text 如何加入eslint
- hive UDAF详解
- css命名规范和样式规范
- 高精度加法
- 【《Real-Time Rendering 3rd》 提炼总结】(三) 第三章 · GPU渲染管线与可编程着色器 The Graphics Processing Unit
- 移动端架构经验
- Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
- Struts2文件上传与下载(中文名称的文件正常上传与下载)
- Redis-cli
- Nginx 配置不当造成加载静态资源件提示ERR_CONTENT_LENGTH_MISMATCH解决方法
- JSON
- char 和 vachar 区别