当前位置:网站首页>Template_ Large integer subtraction_ Regardless of size
Template_ Large integer subtraction_ Regardless of size
2022-07-04 20:06:00 【This question AC sleep again】
//
#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 )
{ // Why can't you flip directly in the function
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;
}
边栏推荐
- The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
- How is the entered query SQL statement executed?
- [QNX Hypervisor 2.2用户手册]6.3.1 工厂页和控制页
- Socket programming demo II
- [graduation season] green ant new fermented grains wine, red mud small stove. If it snows late, can you drink a cup?
- Crystal optoelectronics: ar-hud products of Chang'an dark blue sl03 are supplied by the company
- 1008 elevator (20 points) (PAT class a)
- Niuke Xiaobai month race 7 F question
- @transactional滥用导致数据源连接池耗尽问题
- 实战模拟│JWT 登录认证
猜你喜欢
多表操作-外连接查询
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
HMM hidden Markov model and code implementation
Several methods of online database migration
Multi table operation inner join query
Euler function
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
上线首月,这家露营地游客好评率高达99.9%!他是怎么做到的?
[problem] Druid reports exception SQL injection violation, part always true condition not allow solution
Chrome development tool: what the hell is vmxxx file
随机推荐
kotlin 条件控制
【毕业季】绿蚁新醅酒,红泥小火炉。晚来天欲雪,能饮一杯无?
需求开发思考
socket编程demo二
Chrome开发工具:VMxxx文件是什么鬼
Key rendering paths for performance optimization
kotlin 类和对象
[problem] Druid reports exception SQL injection violation, part always true condition not allow solution
C语言-入门-基础-语法-流程控制(七)
Pytoch learning (4)
HDU 6440 2018 Chinese college student program design network competition
Jetpack Compose 教程
做社交媒体营销应该注意些什么?Shopline卖家的成功秘笈在这里!
New wizard effect used by BCG
HMM hidden Markov model and code implementation
1007 Maximum Subsequence Sum(25 分)(PAT甲级)
实战模拟│JWT 登录认证
双冒号作用运算符以及命名空间详解
[QNX hypervisor 2.2 user manual]6.3.1 factory page and control page
Decryption function calculates "task state and lifecycle management" of asynchronous task capability