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. XML FREESWITCH APPLICATION 实现

    XML XML在FS(FreeSwitch)中进行了大量的使用,其中dialplan就是其中非常主要的一快内容.通过下面的描述,我们可以知道在执行XML中的语句: <action applica ...

  2. HUNNU--湖师大--11410--Eligibility

    [I] Eligibility Regional Contest Director Osama Ismail knows that an individual cannot participate i ...

  3. 指针-->字符串

    1. 以字符串形式出现的,编译器都会为该字符串自动添加一个0作为结束符. 如在代码中写"abc",那么编译器帮你存储的是"abc\0". 2. "ab ...

  4. Swift学习笔记 - 函数与闭包

    import Foundation //1.函数的定义与调用//以 func 作为前缀,返回箭头 -> 表示函数的返回类型func sayHello(name: String) -> St ...

  5. STL中的find_if函数

      上一篇文章也讲过,find()函数只能处理简单类型的内容,也就是缺省类型,如果你想用一个自定义类型的数据作为查找依据则会出错!这里将讲述另外一个函数find_if()的用法 这是find()的一个 ...

  6. [转] Python 模块学习:os模块

    一.os模块概述 Python os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.(一语中的) 二.常用方法 1.os.name 输出字符串指示正在使用的平台 ...

  7. linux下常用基本命令操作

    #fdisk -l 查看硬盘信息 cat /proc/cpuinfo 查看CPU信息 free -m 查看内存信息 ethtool eth0 查看网卡信息 df -h 查看硬盘各分区可用空间大小 ca ...

  8. POJ 1556 The Doors 线段判交+Dijkstra

    The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6734   Accepted: 2670 Descrip ...

  9. ShareSDK.xml 配置

    简要说明 <ShareSDK AppKey="1089fa233237e" /> <!-- 修改成你在sharesdk后台注册的应用的appkey" - ...

  10. nyoj 623

    #include <iostream> using namespace std; int main() { int a[51][51],b[51][51],c[51][51],i,j,k, ...