Description

 

Input

输入A,B
 

Output

输出A+B。

Sample Input

1 1

Sample Output

2

HINT

对于100%的数据,保证 |A| , |B| 不会超过10^(10^7)

呃……高精a+b和a-b的模板题

没啥技术含量的……我还以为会有什么--0之类的出现

#include<cstdio>
#include<cstring>
#define N 10000010
int a[N],b[N],c[N],l1,l2,l3;
char ch1[N],ch2[N];
bool m1,m2;
inline int max(int a,int b){return a>b?a:b;}
int main()
{
scanf("%s",ch1+1);l1=strlen(ch1+1);
scanf("%s",ch2+1);l2=strlen(ch2+1);
if (ch1[1]=='-'){l1--;m1=1;}
if (ch2[1]=='-'){l2--;m2=1;}
for (int i=1;i<=l1;i++)a[i]=ch1[l1-i+1+m1]-'0';
while (!a[l1]&&l1>1)l1--;
if (l1==1&&!a[1])m1=0;
for (int i=1;i<=l2;i++)b[i]=ch2[l2-i+1+m2]-'0';
while (!b[l2]&&l2>1)l2--;
if (l2==1&&!b[1])m2=0;
l3=max(l1,l2);
if (m1^m2)
{
if (m1)
{
for (int i=1;i<=l3;i++)
{
int t=a[i];
a[i]=b[i];
b[i]=t;
}
int t=l1;l1=l2;l2=t;
}
bool mrk=0;
if (l2>l1)mrk=1;
else if (l1==l2)
{
for (int i=l1;i>=1;i--)
if (a[i]<b[i]){mrk=1;break;}
else if (a[i]>b[i])break;
}
if (mrk)
{
printf("-");
for (int i=1;i<=l3;i++)
{
int t=a[i];
a[i]=b[i];
b[i]=t;
}
int t=l1;l1=l2;l2=t; }
for (int i=1;i<=l3;i++)
{
a[i]-=b[i];
if (a[i]<0)
{
a[i]+=10;
int p=i+1;
while (a[p]==0)
{
a[p]=9;
p++;
}
a[p]--;
}
}
while (l3>1&&!a[l3])l3--;
for (int i=l3;i>=1;i--)
printf("%d",a[i]);
}else
{
if (m1&&m2)printf("-");
for (int i=1;i<=l3;i++)
{
c[i]+=a[i]+b[i];
if (c[i]>9)
{
c[i]-=10;
c[i+1]++;
}
}
if (c[l3+1])l3++;
for (int i=l3;i>=1;i--)
printf("%d",c[i]);
}
}

bzoj3767 A+B Problem加强版的更多相关文章

  1. bzoj3767A+B Problem加强版

    bzoj3767A+B Problem加强版 题意: 求两个数的和,每个数绝对值≤10^(10^7). 题解: 又用Python水过了…… 代码: a=raw_input() b=a.split() ...

  2. 打FFT时中发现的卡常技巧

    题目:洛谷P1919 A*B Problem 加强版 我的代码完全借鉴boshi,然而他380ms我880ms...于是我通过彻底的卡(chao)常(dai)数(ma)成功优化到了380ms,都是改了 ...

  3. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  4. 算法笔记_093:蓝桥杯练习 Problem S4: Interesting Numbers 加强版(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its d ...

  5. java实现 蓝桥杯 算法提高 Problem S4: Interesting Numbers 加强版

    1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its digits consists of o ...

  6. HDU 4578 - Transformation - [加强版线段树]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4578 Problem Description Yuanfang is puzzled with the ...

  7. POJ 3294 Life Forms [最长公共子串加强版 后缀数组 && 二分]

    题目:http://poj.org/problem?id=3294 Life Forms Time Limit: 5000MS   Memory Limit: 65536K Total Submiss ...

  8. 3551: [ONTAK2010]Peaks加强版

    3551: [ONTAK2010]Peaks加强版 https://www.lydsy.com/JudgeOnline/problem.php?id=3551 分析: kruskal重构树 +  倍增 ...

  9. 贞鱼传教&&贞鱼传教(数据加强版)

    http://acm.buaa.edu.cn/problem/1381/ 贞鱼传教[问题描述] 新的一年到来了,贞鱼哥决定到世界各地传授“贞教”,他想让“贞教”在2016年成为世界第四大宗教.说干就干 ...

随机推荐

  1. BitBlt介绍

    设备上下文画图有非常多种方法.比如通过创建位图画刷,利用其填充一个区域来实现图像的绘制.此外,还能够使用CDC类的位图函数来输出位图到设备上下文中. BitBlt 用于从原设备中复制位图到目标设备,语 ...

  2. unity3d Find()使用

    1. Hierarchy 创建对象如两个cube时,未修改名称,名称都为cube时. js添加至Camera: private var cubeObj : GameObject; //private ...

  3. 从零开始写一个Tomcat(壹)

    Tomcat是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,也是一个servlet容器的优秀解决方案,做Java web开发的基本上都使用过,但是tomcat大多时间对于我们是一个黑 ...

  4. xheditor编辑器上传截图图片抓取远程图片代码

    xheditor是一款很不错的开源编辑器,用起来很方便也很强大. 分享一个xheditor直接上传截图的问题解决方法. 第一步.设置参数 localUrlTest:/^https?:\/\/[^\/] ...

  5. CentOS 7 修改hostname

    centOS 7 里面修改hostname的方式有所改变,修改/etc/hosts和/etc/sysconfig/network两个文件已经不能生效.使用的新命令是 : hostnamectl set ...

  6. IO-序列化 Serializable Parcelable Object

    简介 1.什么是序列化和反序列化 对象的寿命通常随着生成该对象的程序的终止而终止,有时候,可能需要将对象的状态保存下来,在需要时再将对象恢复.我们把对象的这种,能记录自己的状态以便将来再生的能力,叫作 ...

  7. 函数学习(JY07-JavaScript-JS基础03)

  8. 2015-09-28 Javascript

    1.Javascript是什么? JavaScript是一种脚本语言,结构简单,使用方便,其代码可以直接放入HTML文档中,可以直接在支持JavaScript的浏览器中运行.JavaSript. Ja ...

  9. spring-qualifier解释

    如果一个class有两个对应的beanId,在Autowired的时候,必须指定Qualifier("指定其中一个beanId"). org.springframework.bea ...

  10. MVC验证码的编写

    主要是相互学习一下mvc,希望各位大神指导 /// <summary> /// 生成随机数字 /// </summary> /// <returns>随机数字< ...