bzoj3767 A+B Problem加强版
Description
Input
Output
输出A+B。
Sample Input
Sample Output
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加强版的更多相关文章
- bzoj3767A+B Problem加强版
bzoj3767A+B Problem加强版 题意: 求两个数的和,每个数绝对值≤10^(10^7). 题解: 又用Python水过了…… 代码: a=raw_input() b=a.split() ...
- 打FFT时中发现的卡常技巧
题目:洛谷P1919 A*B Problem 加强版 我的代码完全借鉴boshi,然而他380ms我880ms...于是我通过彻底的卡(chao)常(dai)数(ma)成功优化到了380ms,都是改了 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- 算法笔记_093:蓝桥杯练习 Problem S4: Interesting Numbers 加强版(Java)
目录 1 问题描述 2 解决方案 1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its d ...
- java实现 蓝桥杯 算法提高 Problem S4: Interesting Numbers 加强版
1 问题描述 Problem Description We call a number interesting, if and only if: 1. Its digits consists of o ...
- HDU 4578 - Transformation - [加强版线段树]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4578 Problem Description Yuanfang is puzzled with the ...
- POJ 3294 Life Forms [最长公共子串加强版 后缀数组 && 二分]
题目:http://poj.org/problem?id=3294 Life Forms Time Limit: 5000MS Memory Limit: 65536K Total Submiss ...
- 3551: [ONTAK2010]Peaks加强版
3551: [ONTAK2010]Peaks加强版 https://www.lydsy.com/JudgeOnline/problem.php?id=3551 分析: kruskal重构树 + 倍增 ...
- 贞鱼传教&&贞鱼传教(数据加强版)
http://acm.buaa.edu.cn/problem/1381/ 贞鱼传教[问题描述] 新的一年到来了,贞鱼哥决定到世界各地传授“贞教”,他想让“贞教”在2016年成为世界第四大宗教.说干就干 ...
随机推荐
- HDU 5266 pog loves szh III (线段树+在线LCA转RMQ)
题目地址:HDU 5266 这题用转RMQ求LCA的方法来做的很easy,仅仅须要找到l-r区间内的dfs序最大的和最小的就能够.那么用线段树或者RMQ维护一下区间最值就能够了.然后就是找dfs序最大 ...
- jquery图片滚动
注:代码来自17sucai网,已去除部分冗余代码,只保留图片效果 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional// ...
- csv操作帮助类
功能描述: 集合转换为csv数据 DataSe转换为csv数据 using System; using System.Collections.Generic; using System.Data; u ...
- RHEL7使用ssm命令管理LVM
1.安装ssm [root@localhost ~]# yum -y install system-storage-manager.noarch 2.检查硬盘和LVM信息 [root@localho ...
- 配置keil MDK和keil C51共存
配置keil MDK和keil C51共存:1.首先安装keilMDK或者安装KeilC51其中一个:2.安装到D:\keil路径下,按照默认的配置安装,完成:3.使用管理员身份打开安装好的软件,打开 ...
- 图片样式 scaleType 属性
ImageView的属性android:scaleType,即ImageView.setScaleType(ImageView.ScaleType),不同值的意义区别:
- jQuery事件与动画
一 事件 1 加载DOM事件 $(document).ready():执行时机:DOM元素准备就绪 执行次数:多次 简单写法:原:$(document).ready(function(){}) ...
- javascript基础之javascript的存在形式和js代码块在页面中的存放位置
1.存在形式 文件 如: <script src='js/jc.js'></script> 前页面 <script type='text/javascript'>a ...
- sqlyog使用注意事项
在sqlyog中执行sql语句时,如果sql语句没有加limit 0,1000; sqlyog会自动查询从0开始的1000条,结果导致mysql慢查系统中显示的sql语句末尾加上了limit 0,10 ...
- Git简明教程
http://www.jianshu.com/p/16ad0722e4cc http://www.jianshu.com/p/f7ec8310ccd2