当前位置:网站首页>Haut OJ 1347: addition of choice -- high progress addition
Haut OJ 1347: addition of choice -- high progress addition
2022-07-05 05:17:00 【hunziHang】
Problem description :
It's getting colder and colder in winter ,Choice Of course, I don't want to make everyone cooler , So she gives two integers A,B, You just have to calculate A+B The sum of .
Input :
Multiple groups of input data .
Enter two integers per row A,B
A and B The length of is less than 1000(A,B It's all nonnegative )
Output :
Output A+B Result
The sample input :
1 1 1 2
Sample output :
2 3
Cause analysis :
High progress Algorithm :
1. First create two int Array , And two strings ( Or two char Type array ),int Array initialization , Take the first cell record of the array Data length , And string or char Number in array Single Deposit in int In the array ( Deposit it backwards )
2. find The maximum length of two numbers , then +1( It is only possible to add 1 position , Because the maximum number of rounding is one )
Add two arrays , take i The numbers on the unit are stored in i and i+1 In the unit ( a[i+1] + =a[i]/10;)
3. Remove the leading 0, Because it used to be upside down , So from the len Start Gradually decrease 1
Solution :
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
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],i,j,len;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
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';
len=max(a[0],b[0])+1;
for(i=1;i<=len;i++)
{
a[i]+=b[i];
a[i+1]+=a[i]/10;
a[i]%=10;
}
while(len>1&&a[len]==0)
len--;
for(i=len;i>=1;i--)
cout<<a[i];
cout<<endl;
}
return 0;
}边栏推荐
- 2022/7/1 learning summary
- 2022/7/1学习总结
- National teacher qualification examination in the first half of 2022
- [turn to] MySQL operation practice (I): Keywords & functions
- Web APIs DOM节点
- cocos2dx_ Lua particle system
- UE4/UE5 虚幻引擎,材质篇,纹理,Compression and Memory压缩和内存
- The present is a gift from heaven -- a film review of the journey of the soul
- What is the agile proportion of PMP Exam? Dispel doubts
- Reverse one-way linked list of interview questions
猜你喜欢

C4D simple cloth (version above R21)

Reverse one-way linked list of interview questions

stm32Cubemx(8):RTC和RTC唤醒中断

Merge sort

Chinese notes of unit particle system particle effect
![[to be continued] [UE4 notes] L1 create and configure items](/img/20/54ba719be2e51b7db5b7645b361e26.jpg)
[to be continued] [UE4 notes] L1 create and configure items

【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research

Embedded database development programming (VI) -- C API

BUUCTF MISC

2021-10-29
随机推荐
What is the agile proportion of PMP Exam? Dispel doubts
Leetcode word search (backtracking method)
Time format conversion
Es module and commonjs learning notes
cocos2dx_ Lua card flip
Generate filled text and pictures
[allocation problem] 135 Distribute candy
64 horses, 8 tracks, how many times does it take to find the fastest 4 horses at least
[sum of two numbers] 169 sum of two numbers II - enter an ordered array
[binary search] 69 Square root of X
[turn]: Apache Felix framework configuration properties
The difference between heap and stack
2022/7/1学习总结
Kali 2018 full image download
Unity sends messages and blocks indecent words
Use the command character to close the keyboard command of the notebook
Ue4/ue5 illusory engine, material part (III), material optimization at different distances
2022 / 7 / 1 Résumé de l'étude
Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
PR first time