본문 바로가기

Algorithm/Code Fights (Code Signal)

Aracade Intro #38 growingPlant. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar

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/10 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #37 arrayMaxConsecutiveSum. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar

2018/12/10 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #36 differentSymbolsNaive. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar

2018/11/29 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #35 firstDigit. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar

2018/11/26 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #34 extractEachKth. Algorithm, 알고리즘, Codefights, CodeSignal, 코드파이트, 코드시그널, 예제, example, c++ java c# scalar



2018/11/28 - [Programming/Image Processing] - OpenCV How to get min/max value from matrix, 매트릭스 최소값/최대값. Java,c++,cpp,imageprocessing

2018/11/28 - [Programming/Image Processing] - OpenCV How to handle single channel image matrix each pixel, add/subtract/multiply/division (1), 이미지 매트릭스 각 픽셀단위 값 조정하기 (영상처리, image processing) (1)


2018/11/27 - [Programming/Image Processing] - OpenCV Java complexNumber mat conjugation, 자바 켤레복소수 example code 예제코드


2018/11/26 - [Programming/Java] - Arithmetic of complex number(2) division example code, 복소수 사칙연산(2) 나눗셈 코드, real/imaginary, java, opencv, matrix (2)



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 효능/부작용/성인,소아 용법