高精度加法——经典题 洛谷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 ...
随机推荐
- 用JavaScript比较两个数组是否相等
JS怎么比较两个数组是否有完全相同的元素?Javascript不能直接用==或者===来判断两个数组是否相等,无论是相等还是全等都不行,以下两行JS代码都会返回false alert([0,0,0]= ...
- [python]html格式转md格式
html格式转md格式 # 模块html2text pip install html2text/pip3 install html2text 测试: import html2text as ht te ...
- ieda 快捷键修改方法
框中意思为: 1.增加快捷键 2.增加缩写
- java中的JSON数据转换方法fastjson
1 maven工程引入fastjson <?xml version="1.0" encoding="UTF-8"?> <project xml ...
- libcrypto.so.1.0.0: no version information available
openssl-1.0.1p源码安装后,依赖于openssl.so库的应用报错libcrypto.so.1.0.0: no version information available 解法:1. 创建 ...
- C语言实验一(1)
#include<stdio.h>int main(){ int a,b,sum; a=123; b=456; sum=a+b; printf("sum is %d\n" ...
- UML入门学习
在UML类图中,常见的有以下几种关系: 泛化(Generalization), 实现(Realization),关联(Association),聚合(Aggregation),组合(Composit ...
- 通讯录管理系统(C语言)
/* * 对通讯录进行插入.删除.排序.查找.单个显示功能 */ #include <stdio.h> #include <malloc.h> #include <str ...
- python正则表达式补充
import re origin= "hello alex bcd alex 1ge alex acd 19" r=re.match("(?P<n1>h)(? ...
- spring(AOP)静态代理
姓名:黄于霞 班级:软件151 1.定义抽象主题接口,假设需实现一个计算的类Math.完成加.减.乘.除功能,如下所示: 2.主题类,算术类,实现抽象接口. 3.代理类 4.测试运行 5.总 ...