MapleStory Finger Point Cute Line Smiley Blinking Hello Kitty Angel MapleStory Finger Point

๐Ÿƒ‍โ™€๏ธprogrammers/Java

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - java 1๋กœ ๋งŒ๋“ค๊ธฐ

HYEJU01 2024. 5. 7. 11:04

 

๐Ÿ’กwhile ๋ฌธ๊ณผ for ๋ฌธ์„ ์ด์šฉํ•ด์„œ ํ’€์–ด์ฃผ๋ฉด ๋œ๋‹ค!
1์ด ๋˜๋ฉด answer ๊ฐ’์„ ์ฆ๊ฐ€์‹œํ‚ค๋ฏ€๋กœ

while ์˜ ์กฐ๊ฑด๋ฌธ์„ 1์ด ๋˜๊ธฐ ์ „๊นŒ์ง€๋กœ ์„ค์ •ํ•ด์ฃผ๋ฉด ๋œ๋‹ค. (num_list[i] != 1)

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

int solution(int num_list[], size_t num_list_len) {
    int answer = 0;
    int num = 0 ;

        for (int i = 0 ; i < num_list_len; i++){
            while(num_list[i] != 1) {
                if (num_list[i] % 2 == 0 ){
                    num_list[i] /= 2; 
                    
                } else {
                    num_list[i] -= 1;
                    num_list[i] /= 2;
                }   
                answer++;
            } 
        }   
    return answer;
}