高精度加法——经典题 洛谷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 ...
随机推荐
- Spark2.X管理与开发
==========第一篇:Scala编程语言========= 一.Scala语言基础 1.Scala语言简介 Scala是一种多范式的编程语言,其设计的初衷是要集成面向对象编程和函数式编程的各 ...
- PyQt5——布局管理
PyQt5布局管理使用方法详见:https://blog.csdn.net/jia666666/article/list/3?t=1& PyQt5布局管理汇总: 1.QHBoxLayout 2 ...
- 第 9 章 数据管理 - 074 - 如何安装和配置 Rex-Ray?
Rex-Ray 安装和配置方法 Rex-Ray 是一个优秀的 Docker volume driver 安装和配置方法 Rex-Ray 以 standalone 进程的方式运行在 Docker 主机上 ...
- Go语言学习之11 日志收集系统kafka库实战
本节主要内容: 1. 日志收集系统设计2. 日志客户端开发 1. 项目背景 a. 每个系统都有日志,当系统出现问题时,需要通过日志解决问题 b. 当系统机器比较少时,登陆到服务器上查看即可 ...
- git add * 提示warning: LF will be replaced by CRLF in 解决办法
在使用git的时候,每次执行 $ git add * 都会提示这样一个警告消息: 虽然说没有什么影响吧. 不过就是觉得太碍眼了, 按照这样设置就没有问题了: git config core.autoc ...
- dedecmsV5.7织梦后台更新文章,发布时间不自动更新
问题:dedecmsV5.7后台修改文章的时候,会更新发布时间,需求是不自动更新时间,还是当时的发布时间 解决: 1.修改后台文件夹/templets/archives_edit.htm,articl ...
- jquery 根据文本设置选中某个选项
<select name="streetid" id="streetid"> <option value="4">a ...
- [luogu P3065] [USACO12DEC]第一!First!
[luogu P3065] [USACO12DEC]第一!First! 题目描述 Bessie has been playing with strings again. She found that ...
- js判重
1.两个数组,取出不重复的部分 var arr=[1,2,3]; var arr1=[1,2]; vat tmp=[]; for(let i in arr1){ if(!(arr.includes(a ...
- java8 简便的map和list操作
如果你看到这篇文章,说明你对java繁琐的list和map操作产生了厌烦.在java中,频繁的操作基本上是获取到对象list,然后根据某个属性或者某几个属性的值,把list转为map,然后遍历其他对象 ...