当前位置:网站首页>模板_大整数减法_无论大小关系
模板_大整数减法_无论大小关系
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;
}边栏推荐
- MXNet对GoogLeNet的实现(并行连结网络)
- How is the entered query SQL statement executed?
- 力扣刷题日记/day6/6.28
- Is it safe to open an account online? is that true?
- vbs或vbe如何修改图标
- 力扣刷题日记/day1/2022.6.23
- LD_ LIBRARY_ Path environment variable setting
- Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
- Reptile elementary learning
- [mathematical modeling of graduate students in Jiangxi Province in 2022] analysis and code implementation of haze removal by nucleation of water vapor supersaturation
猜你喜欢

Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines

My colleagues quietly told me that flying Book notification can still play like this

Li Kou brush question diary /day7/6.30

字节跳动Dev Better技术沙龙成功举办,携手华泰分享Web研发效能提升经验

爬虫初级学习

Neglected problem: test environment configuration management

力扣刷题日记/day1/2022.6.23

Nature microbiology | viral genomes in six deep-sea sediments that can infect Archaea asgardii

Halcon template matching

同事悄悄告诉我,飞书通知还能这样玩
随机推荐
Scala基础教程--17--集合
Caché WebSocket
力扣刷题日记/day7/6.30
LD_ LIBRARY_ Path environment variable setting
Scala基础教程--12--读写数据
Android uses sqliteopenhelper to flash back
Interview summary of large factory Daquan II
2022年字节跳动日常实习面经(抖音)
ESP32-C3入门教程 问题篇⑫——undefined reference to rom_temp_to_power, in function phy_get_romfunc_addr
6.26cf simulation match B: solution to array reduction problem
[210] usage of PHP delimiter
Scala基础教程--14--隐式转换
Mxnet implementation of googlenet (parallel connection network)
一种将Tree-LSTM的强化学习用于连接顺序选择的方法
Blue bridge: sympodial plant
MXNet对GoogLeNet的实现(并行连结网络)
Li Kou brush question diary /day4/6.26
Scala基础教程--20--Akka
Imitation of numpy 2
Is it safe to download the mobile version of Anxin securities and open an account online