当前位置:网站首页>模板_大整数减法_无论大小关系
模板_大整数减法_无论大小关系
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;
}
边栏推荐
- Scala basic tutorial -- 19 -- actor
- 激进技术派 vs 项目保守派的微服务架构之争
- [go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors
- [system disk back to U disk] record the operation of system disk back to U disk
- 力扣刷題日記/day6/6.28
- Just today, four experts from HSBC gathered to discuss the problems of bank core system transformation, migration and reconstruction
- Is it safe to open an account online? is that true?
- Reptile elementary learning
- Blue bridge: sympodial plant
- How to open an account is safe,
猜你喜欢
TCP waves twice, have you seen it? What about four handshakes?
Principle and application of ThreadLocal
Machine learning concept drift detection method (Apria)
[HCIA continuous update] WAN technology
MXNet对GoogLeNet的实现(并行连结网络)
Thawte通配符SSL证书提供的类型有哪些
Reptile elementary learning
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
Scala基础教程--16--泛型
[mathematical modeling of graduate students in Jiangxi Province in 2022] analysis and code implementation of haze removal by nucleation of water vapor supersaturation
随机推荐
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
[211] go handles the detailed documents of Excel library
2022 ByteDance daily practice experience (Tiktok)
【2022年江西省研究生数学建模】水汽过饱和的核化除霾 思路分析及代码实现
Halcon模板匹配
Is it safe to download the mobile version of Anxin securities and open an account online
谷粒商城(一)
2022年字节跳动日常实习面经(抖音)
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
C语言打印练习
My colleagues quietly told me that flying Book notification can still play like this
激进技术派 vs 项目保守派的微服务架构之争
Torchdrug tutorial
ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
【系统盘转回U盘】记录系统盘转回U盘的操作
线上MySQL的自增id用尽怎么办?
力扣刷题日记/day8/7.1
完善的js事件委托
Thawte通配符SSL证书提供的类型有哪些
【OpenCV入门到精通之九】OpenCV之视频截取、图片与视频互转