当前位置:网站首页>大整数的加与乘;
大整数的加与乘;
2022-06-12 02:55:00 【HENU_Lzey】
大整数的加与乘;
1.加
#include<bits/stdc++.h>
using namespace std;
int a[10000],b[10000],c[10000];
char a1[10000],b1[10000];
int cnt,i,j;
int main(){
cin>>a1>>b1;
int lena=strlen(a1);
int lenb=strlen(b1);
int len=max(lena,lenb)+1;
for(i=1;i<=lena;i++)a[i]=a1[lena-i]-'0';
for(i=1;i<=lenb;i++)b[i]=b1[lenb-i]-'0';
for(i=1;i<=len;i++){
c[i]+=a[i]+b[i];
c[i+1]=c[i]/10;
c[i]=c[i]%10;
}
while(c[len]==0&&len>1)len--;
for(i=len;i>=1;i--)cout<<c[i];
return 0;
}
大整数乘法;
#include<bits/stdc++.h>
using namespace std;
char a1[10001],b1[10001];//定义此数组的目的是为了便于输入;
int a[10001],b[10001],c[10001];
int i,len,j;
int main ()
{
cin>>a1>>b1;//
int lena=strlen(a1);//
int lenb=strlen(b1);//
for(i=1;i<=lena;i++)a[i]=a1[lena-i]-'0';//倒序输入;
for(i=1;i<=lenb;i++)b[i]=b1[lenb-i]-'0';//倒序输入;
for(i=1;i<=lenb;i++)
for(j=1;j<=lena;j++)
c[i+j-1]+=a[j]*b[i];//在计算乘法的时候先不考虑进位,之后再加上去就行。
for(i=1;i<lena+lenb;i++)//j是指正常的计算进位(一位一位进行乘法计算),而i就是我们说的错位相加。
if(c[i]>9)//此时再考虑进位;
{
c[i+1]+=c[i]/10;
c[i]%=10;
}
len=lena+lenb;
while(c[len]==0&&len>1)len--;//去除前导零 ;
for(i=len;i>=1;i--)cout<<c[i];//倒序输出;
return 0;
}
边栏推荐
- [digital signal processing] correlation function (energy signal | cross correlation function of energy signal | autocorrelation function of energy signal)
- I2C protocol overview
- 余压监控系统在高层民用建筑的应用
- Demand and business model innovation - demand 11 - overview of demand analysis
- Unity3D中DrawCall、Batches、SetPassCall
- $. map(data,function(item,index){return XXX})
- Hypergraph tilted data is merged into root node and transferred to 3dfiles
- JSON and XML pros and cons
- 函数模板 Function Templates
- Intel case
猜你喜欢

ARD3M电动机保护器在煤炭行业中的应用

Start ticwatch2

余压监控系统在高层民用建筑的应用

推荐6款办公软件,好用还免费,效率翻倍

Exemple de projet d'applet Wechat - calculatrice de constitution

ssh公钥登录失败报错:sign_and_send_pubkey: no mutual signature supported

WPS table learning notes - highlight duplicate values

The program actively carries out telephone short message alarm, and customizes telephone, short message and nail alarm notifications

Intel case

(9) Serial port interrupt
随机推荐
alertmanager告警配置
安科瑞抗晃电产品在河北某化工项目的应用
Don't rush to work after the college entrance examination. There are plenty of opportunities after working. It's not bad for these three months
maya前臺渲染插件mel脚本工具
Intel case
WPS table learning notes - highlight duplicate values
微信小程序项目实例——我有一支画笔(画画)
Bochuang smart sprint technology innovation board: annual revenue of RMB 1.1 billion, book value of accounts receivable of RMB 300million
A single quarter of educational technology revenue of 230million: a year-on-year decrease of 51% and a sharp narrowing of net loss
Apply concentrated load to nodes in batch in ABAQUS
oracle之用户和表空间
Android HTML5 page load cache optimization
I2C protocol overview
Comment prévenir les incendies électriques dans les centres commerciaux?
Unity3D中DrawCall、Batches、SetPassCall
Force deduction solution summary 462- minimum number of moves to make array elements equal II
Demand and business model innovation - demand 8- interview
Computer common sense
For the first time, why not choose "pure medium platform" for byte beating data platform
Depth copy