当前位置:网站首页>模板_大整数减法_无论大小关系
模板_大整数减法_无论大小关系
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基础教程--17--集合
- Android uses sqliteopenhelper to flash back
- Machine learning concept drift detection method (Apria)
- Li Kou brush question diary /day4/6.26
- Imitation of numpy 2
- Is it safe to open an account online? is that true?
- 输入的查询SQL语句,是如何执行的?
- 完善的js事件委托
- [mathematical modeling of graduate students in Jiangxi Province in 2022] analysis and code implementation of haze removal by nucleation of water vapor supersaturation
- Unity makes revolving door, sliding door, cabinet door drawer, click the effect of automatic door opening and closing, and automatically play the sound effect (with editor extension code)
猜你喜欢

【2022年江西省研究生数学建模】冰壶运动 思路分析及代码实现

中国农科院基因组所汪鸿儒课题组诚邀加入

力扣刷题日记/day7/2022.6.29

蓝桥:合根植物

TCP waves twice, have you seen it? What about four handshakes?

基于C语言的菜鸟驿站管理系统

1、 Introduction to C language

. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)

一、C语言入门基础

ThreadLocal原理与使用
随机推荐
Li Chi's work and life summary in June 2022
What types of Thawte wildcard SSL certificates provide
What if the self incrementing ID of online MySQL is exhausted?
力扣刷题日记/day4/6.26
Unity makes revolving door, sliding door, cabinet door drawer, click the effect of automatic door opening and closing, and automatically play the sound effect (with editor extension code)
LD_ LIBRARY_ Path environment variable setting
线上MySQL的自增id用尽怎么办?
Caché JSON 使用JSON适配器
LD_LIBRARY_PATH 环境变量设置
其他InterSystems %Net工具
Scala basic tutorial -- 18 -- set (2)
VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
Li Kou brush question diary /day8/7.1
Scala基础教程--20--Akka
Blue bridge: sympodial plant
Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
File processing examples of fopen, FREAD, fwrite, fseek
力扣刷題日記/day6/6.28
Esp32-c3 introductory tutorial questions ⑫ - undefined reference to ROM_ temp_ to_ power, in function phy_ get_ romfunc_ addr
Thawte通配符SSL证书提供的类型有哪些