当前位置:网站首页>Haut OJ 1357: lunch question (I) -- high precision multiplication
Haut OJ 1357: lunch question (I) -- high precision multiplication
2022-07-05 05:17:00 【hunziHang】
Problem description :
12 It's o'clock again , It's time for lunch , Small C Collapse in bed and don't want to get up , Small A Don't want to get used to him , So I said to him :“ Small C, You didn't make it last week choice Sister's addition , Now you can make choice Sister's multiplication , I'll bring you some rice .” Can you help me C.
Input :
Two integers A and B,A and B The length of l(0 <= l <= 1000).
Output :
Multi instance testing , Output A*B Result .
The sample input :
4038 5255 55718 7221 8160 104906 3511906 8767574
Sample output :
21219690 402339678 856032960 30790895736044
Cause analysis :
1. Create three int Array , Initialize to 0, Record length , Save each number in the string into the array cell ( Input backwards )
2. Multiply each number , c[i+j-1] + =a[i]*b[j]; c[i+j]+=c[i+j-1]/10; Don't let it slip +
3. Remove leading 0
Solution :
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
long long a[1000005];
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string str1,str2;
while(cin>>str1>>str2)
{
int a[2000],b[2000],c[5000],i,j,len;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
a[0]=str1.length();
b[0]=str2.length();
for(i=1;i<=a[0];i++)
a[i]=str1[a[0]-i]-'0';
for(i=1;i<=b[0];i++)
b[i]=str2[b[0]-i]-'0';
for(i=1;i<=a[0];i++)
for(j=1;j<=b[0];j++)
{
c[i+j-1]+=a[i]*b[j];
c[i+j]+=c[i+j-1]/10;
c[i+j-1]%=10;
}
len=a[0]+b[0]+1;
while(len>1&&c[len]==0)
len--;
for(i=len;i>=1;i--)
cout<<c[i];
cout<<endl;
}
return 0;
}
边栏推荐
猜你喜欢

Research on the value of background repeat of background tiling
![[depth first search] 695 Maximum area of the island](/img/08/cfff4aec667216e4f146205a12c13f.jpg)
[depth first search] 695 Maximum area of the island

Grail layout and double wing layout

Use of snippets in vscode (code template)

Optimization scheme of win10 virtual machine cluster

Reverse one-way linked list of interview questions

2022/7/2做题总结

Binary search basis

Data is stored in the form of table

远程升级怕截胡?详解FOTA安全升级
随机推荐
Solon Auth 认证框架使用演示(更简单的认证框架)
The present is a gift from heaven -- a film review of the journey of the soul
Stm32cubemx (8): RTC and RTC wake-up interrupt
被舆论盯上的蔚来,何时再次“起高楼”?
Kali 2018 full image download
十年不用一次的JVM调用
服务熔断 Hystrix
BUUCTF MISC
Web APIs DOM节点
Unity intelligent NPC production -- pre judgment walking (method 1)
[转]MySQL操作实战(三):表联结
A three-dimensional button
Lua wechat avatar URL
Embedded database development programming (VI) -- C API
Sixth note
National teacher qualification examination in the first half of 2022
使用命令符关闭笔记本自带键盘命令
Solon 框架如何方便获取每个请求的响应时间?
Double pointer Foundation
Fragment addition failed error lookup