当前位置:网站首页>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;
}
边栏推荐
- UE fantasy engine, project structure
- PR first time
- Es module and commonjs learning notes -- ESM and CJS used in nodejs
- Unity get component
- [sum of two numbers] 169 sum of two numbers II - enter an ordered array
- 《动手学深度学习》学习笔记
- Unity find the coordinates of a point on the circle
- 64 horses, 8 tracks, how many times does it take to find the fastest 4 horses at least
- PMP candidates, please check the precautions for PMP examination in July
- 【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
猜你喜欢
随机推荐
[allocation problem] 135 Distribute candy
Ue4/ue5 illusory engine, material part (III), material optimization at different distances
Solon Logging 插件的添加器级别控制和日志器的级别控制
The next key of win generates the timestamp file of the current day
Unity writes timetables (without UI)
UE fantasy engine, project structure
Listview pull-down loading function
使用Room数据库报警告: Schema export directory is not provided to the annotation processor so we cannot expor
嵌入式数据库开发编程(零)
Establish cloth effect in 10 seconds
C iterator
Personal required code
[binary search] 34 Find the first and last positions of elements in a sorted array
Pointnet++的改进
Panel panel of UI
Unity parallax infinite scrolling background
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
小程序直播+电商,想做新零售电商就用它吧!
质量体系建设之路的分分合合
[turn]: Apache Felix framework configuration properties

![[to be continued] [UE4 notes] L1 create and configure items](/img/20/54ba719be2e51b7db5b7645b361e26.jpg)




![[轉]: OSGI規範 深入淺出](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)


