高精度加法——经典题 洛谷p1601
题目背景
无
题目描述
高精度加法,x相当于a+b problem,[b][color=red]不用考虑负数[/color][/b]
输入输出格式
输入格式:
分两行输入a,b<=10^500
输出格式:
输出只有一行,代表A+B的值
输入输出样例
1
1
2
附上代码:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>//不要问我为什么这么多头文件 闲的
using namespace std;
char a1[],b1[];
int a[],b[],c[];
int main()
{
scanf("%s",a1);scanf("%s",b1);//scanf就爆0!
if(a1[]==&&b1[]==)
{
cout<<""<<endl;
return ;
}
int lena=strlen(a1),lenb=strlen(b1);
for(int i=;i<lena;i++)
{
a[lena-i-]=int(a1[i]-);
}
for(int i=;i<lenb;i++)
{
b[lenb-i-]=int(b1[i]-);//倒序输入便于进位
}
int m=max(lena,lenb);
for(int i=;i<m;i++)
{
c[i]+=a[i]+b[i];//不能直接赋值,要加上前面的进位
while(c[i]>=)
{
c[i+]++;
c[i]-=;
}
}
m++;
while(c[m]==) m--; //删除前导0
for(int i=m;i>=;i--)
cout<<c[i];
cout<<endl;
return ;
}
还是比较简单明了的。
高精度加法——经典题 洛谷p1601的更多相关文章
- 【洛谷p1601】A+B Problem(高精)
高精度加法的思路还是很简单容易理解的 A+B Problem(高精)[传送门] 洛谷算法标签: 附上代码(最近懒得一批) #include<iostream> #include<cs ...
- 洛谷P1601 A+B Problem(高精)
题目描述 高精度加法,x相当于a+b problem,[b][color=red]不用考虑负数[/color][/b] 输入输出格式 输入格式: 分两行输入a,b<=10^500 输出格式: 输 ...
- 洛谷 P1601 A+B Problem(高精)
P1601 A+B Problem(高精) 题目背景 无 题目描述 高精度加法,x相当于a+b problem,[b][color=red]不用考虑负数[/color][/b] 输入输出格式 输入格式 ...
- 【洛谷P1601 A+B Problem(高精)】
题目背景 无 题目描述 高精度加法,x相当于a+b problem,[b][color=red]不用考虑负数[/color][/b] 输入输出格式 输入格式: 分两行输入a,b<=10^500 ...
- 2018.10.30 一题 洛谷4660/bzoj1168 [BalticOI 2008]手套——思路!问题转化与抽象!+单调栈
题目:https://www.luogu.org/problemnew/show/P4660 https://www.lydsy.com/JudgeOnline/problem.php?id=1168 ...
- 洛谷——P1601 A+B Problem(高精)
https://www.luogu.org/problem/show?pid=1601#sub 题目背景 无 题目描述 高精度加法,x相当于a+b problem,[b][color=red]不用考虑 ...
- 题解-洛谷P1601 A+B Problem(高精)
https://www.luogu.org/problemnew/show/P1601(题目传送) 显然数据范围超过了long long类型,故不能简单的用两个长整型存起来相加.这里用到大数据的高精度 ...
- 经典DP 洛谷p1880 石子合并
https://www.luogu.org/problemnew/show/P1880 题目 题目描述 在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新 ...
- AC日记——大爷的字符串题 洛谷 P3709
大爷的字符串题 思路: 莫队,需开O2,不开50: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 20000 ...
随机推荐
- vuex的学习和理解
初识Vuex: vuex是 vue官方推荐的一个状态管理器,也是vue专用的一个插件.当我们遇到很多状态改变时,组件之间的通信就会变得复杂,这时候vuex的强大就体现出来了. Vuex 应用的核心就是 ...
- sublime text3使用
设置tab键为若干空格 { "tab_size": 4, "translate_tabs_to_spaces": true }
- 如何查看linux服务器内存使用情况
1. free命令 free 命令显示系统使用和空闲的内存情况,包括物理内存.交互区内存(swap)和内核缓冲区内存. 直接输入free命令,显示如下 free命令默认是显示单位kb,可以采用fr ...
- requests库爬取猫眼电影“最受期待榜”榜单 --网络爬虫
目标站点:https://maoyan.com/board/6 # coding:utf8 import requests, re, json from requests.exceptions imp ...
- Mac安装python3.x+pycharm+elasticsearch+常见报错处理(1)
---恢复内容开始--- mac安装python有两种方式:此处叙述官网安装下载. mac 自带python2.x版本,python2和3之间的差距还是有的.下面简单叙述我安装python3.7的过程 ...
- C# interface 的隐式与显示实现及适应范围源码演示
把代码过程中经常用到的一些代码段做个记录,如下的资料是关于C# interface 的隐式与显示实现及适应范围演示的代码. interface IAnimal { void Dog(); } clas ...
- vue中是使用富文本编辑器vue-quill-edit
之前使用的富文本编辑器是uEditor,kindEditor,感觉不太方便 近期项目vue单页面,就使用这个编辑器组件吧! 一.安装 cnpm install vue-quill-editor 二. ...
- linux 下的read write 和fread fwrite
待进一步测试啊,先占坑 --------2017/7/17 忘记之前要写什么了,只记得当时测试完得出的结论是,无论是写设备还是写文件,都用read/write是既安全又省事情的举动.还熟悉. 尽多少力 ...
- jsp页面怎么引入js
人老了,容易忘记事情,再此记录 这里需要注意的是js文件夹要直接放在WebRoot或者WebContent文件夹下面,不要放在WEB-INF下面.因为TomCat对WEB-INF这个文件夹下面的资源是 ...
- 软件测试第一次试验JUnit
一.Junit, hamcrest以及eclemma的安装 对于Junit和hamcrest的安装,我并没有从下载Junit和hamcrest相关的jar包然后通过build path导入到项目中,而 ...