当前位置:网站首页>模板_大整数减法_无论大小关系
模板_大整数减法_无论大小关系
2022-07-04 17:14:00 【这题AC再睡.】
//
#include<bits/stdc++.h>
using namespace std;
#define mem( a,v ) memset( a,v,sizeof( a ) )
const int N=11111;
bool f=false;
void re( char *a,char *b )
{ // 为什么不能在函数里面直接翻转
if( strlen(a)>strlen(b) ) return ;
if( strlen(a)<strlen(b) || strcmp( a,b )<0 ) f=true;
}
int main()
{
char a[N],b[N],ans[N];
int len,i;
mem( a,0 ); mem( b,0 ); mem( ans,0 );
cin>>a>>b;
re( a,b );
if( f ) swap( a,b ); // swap
len=strlen(a); // len
reverse( a,a+strlen(a) );
reverse( b,b+strlen(b) );
for( i=0;a[i];i++ ) a[i]-='0';
for( i=0;b[i];i++ ) b[i]-='0';
for( i=0;i<=len;i++ )
{
if( a[i]<b[i] ) a[i+1]--,a[i]+=10;
ans[i]=a[i]-b[i];
}
if( f ) cout<<"-"; // -
for( i=len;i&&ans[i]==0;i-- );
for( ;~i;i-- ) cout<<(int)ans[i]; // int
cout<<endl;
return 0;
}
边栏推荐
- 删除二叉搜索树中的节点附图详解
- TCP waves twice, have you seen it? What about four handshakes?
- Scala基础教程--17--集合
- 大厂面试总结大全二
- Scala basic tutorial -- 14 -- implicit conversion
- [211] go handles the detailed documents of Excel library
- 6.26CF模拟赛E:价格最大化题解
- Principle and application of ThreadLocal
- Thawte通配符SSL证书提供的类型有哪些
- Li Kou brush question diary /day4/6.26
猜你喜欢
Unity 制作旋转门 推拉门 柜门 抽屉 点击自动开门效果 开关门自动播放音效 (附带编辑器扩展代码)
Wireshark packet capturing TLS protocol bar displays version inconsistency
Reptile elementary learning
Numpy 的仿制 2
Basic tutorial of scala -- 16 -- generics
[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation
My colleagues quietly told me that flying Book notification can still play like this
Scala basic tutorial -- 17 -- Collection
Scala basic tutorial -- 15 -- recursion
【Go语言刷题篇】Go完结篇|函数、结构体、接口、错误入门学习
随机推荐
[cloud voice suggestion collection] cloud store renewal and upgrading: provide effective suggestions, win a large number of code beans, Huawei AI speaker 2!
大厂面试总结大全二
6.26cf simulation match B: solution to array reduction problem
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
An example of multi module collaboration based on NCF
力扣刷题日记/day6/6.28
【2022年江西省研究生数学建模】水汽过饱和的核化除霾 思路分析及代码实现
Blue bridge: sympodial plant
How is the entered query SQL statement executed?
完善的js事件委托
基于unity的愤怒的小鸟设计
ThreadLocal原理与使用
Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
[2022 Jiangxi graduate mathematical modeling] curling movement idea analysis and code implementation
Halcon模板匹配
工厂从自动化到数字孪生,图扑能干什么?
Scala basic tutorial -- 20 -- akka
【2022年江西省研究生数学建模】冰壶运动 思路分析及代码实现
I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)
Scala基础教程--14--隐式转换