Aracade Intro #38 growingPlant. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar
Q.
Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed meters due to the lack of sun heat. Initially, plant is 0 meters tall. We plant the seed at the beginning of a day. We want to know when the height of the plant will reach a certain level.
식물이 upSpeed 미터씩 매일 자라난다. 매일밤 downSpeed 미터씩 줄어든다. 처음에 식물은 0미터에서 시작한다. 우리는 하루가 시작할 때 씨앗을 심는다. 우리는 언제 특정 높이까지 다다를지 알고싶다.
e.g.
Input -> upSpeed = 100, downSpeed = 10, and desiredHeight = 910
Output -> growingPlant(upSpeed, downSpeed, desiredHeight) = 10
100 -> 90 -> 190 -> 180 -> 280 -> 270 -> 370 -> 360 -> 460 -> 450 -> 550 -> 540
640 -> 630 -> 730 -> 720 -> 820 -> 810 -> 910
//Process
//1. Input upSpeed, downSpeed, and desiredHeight
//2. Add upSpeed to height
//3. Iterate till height < desiredHeight
// 3.1. Add (upSpeed - downSpeed) to height
// 3.2. Count
//4. Return count
//처리과정
//1. upSpeed, downSpeed, desiredHeight 를 입력받는다.
//2. height 에 upSpeed 를 더한다.
//3. height < desiredHeight 이면 반복한다.
// 3.1. height 에다가 (upSpeed - downSpeed) 를 더한다.
// 3.2. count를 센다.
//4. count 를 반환한다.
Code.. Lemme see code!!!!!
코드.. 코드를 보자!!!!!
int growingPlant(int upSpeed, int downSpeed, int desiredHeight) {
int count = 1;
int height = upSpeed;
while (height < desiredHeight)
{
height += (upSpeed - downSpeed);
++count;
}
return count;
}
Something else you might like..
2018/12/04 - [Life/Health care] - Magnesium 마그네슘 usage/side effects/dosage 용법/효능/부작용
2018/12/03 - [Life/Health care] - Lecithin 레시틴 usage/side effects/dosage 효능/부작용/용법
2018/12/02 - [Life/Health care] - Maca 마카 usage/side effects/dosage 효능/부작용/용법
2018/11/29 - [Life/Health care] - L-Arginine 아르기닌 usage/side effects/dosage 효능/부작용/성인,소아 용법