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. BaseAdapter的ArrayIndexOutOfBoundsException

    最近写一个listView中多个listItem布局时,convertView缓存及使用,类似微信的聊天界面的listView,报了一个异常: 11-25 15:51:49.076: E/InputE ...

  2. 网络编程TCP总结及实践-C语言

    网络变成首先要注意IP和port的转换,如今电脑基本上是主机字节序,存储依照小端方式,而在网络中传输统一使用大端方式,所以网络变成首先要注意字节序的转换. 一个经常使用的ip转换程序的实现: #inc ...

  3. *candy——leetcode

    /* */ #include<iostream> #include<vector> //#include<algorithm> #include <windo ...

  4. Android进程机制

    以下资料摘录整理自老罗的Android之旅博客,是对老罗的博客关于Android底层原理的一个抽象的知识概括总结(如有错误欢迎指出)(侵删):http://blog.csdn.net/luosheng ...

  5. 逆拓扑排序 HDU2647Reward

    这个题如果用邻接矩阵的话,由于n比较大,会超内存,所以选用邻接表的形式.还有就是这个题有那个等级的问题,一级比一级的福利高,所以不能直接拓扑排序,而是反过来,计算出度,找出度为0的顶点,然后更新出度数 ...

  6. spring aop切面配置

    <bean id="aopLog" class="sardine.commodity.biz.AopLog"/>    <aop:config ...

  7. 大型系统开发sql优化总结(转)

    Problem Description: 1.每个表的结构及主键索引情况 2.每个表的count(*)记录是多少 3.对于创建索引的列,索引的类型是什么?count(distinct indexcol ...

  8. libthrift0.9.0解析(三)之TProtocol&TTransport

       以上是transport和protocol的类图和结构图. transport封装了底层的传输通道,主要有read/write.open/close等基本的读写方法,而且都是对于二进制数据. p ...

  9. DWZ简介及其使用

    来源:http://blog.csdn.net/t123012009065/article/details/8286826 DWZ简介:   DWZ富客户端框架(jQuery RIA framewor ...

  10. 26.单片机中利用定时器中断,在主流程while(1){}中设置每隔精确时间计量

    { CountMilliseconds++;//只负责自加,加到最大又重新从0开始 } u16 setDelay(u16 t) { ); } u8 checkDelay (u16 t)//返回非零表示 ...