Notice
Recent Posts
Recent Comments
Link
반응형
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

붕어의 개발 기록

8월 13일 99클럽 항해 23일 본문

항해99(2024-07~08)/99클럽 하루 한문제

8월 13일 99클럽 항해 23일

은붕어_ 2024. 8. 13. 16:41
반응형

99클럽 항해 23일차

 

오늘의 문제는 마법의 엘레베이터이다.

 

문제에서 주어지는 예를 보면 1의 자리 수가 5인 경우 5보다 큰 경우 5보다 작은 경우에 따라 구분을 하며

1의 자리 수가 5인 경우에는 10의 자리 수를 보고 올림을 할지 내림을 할지 판단해야 한다.

 

 

class Solution {
    public int solution(int storey) {
        int answer = 0;
        while(storey!=0) {
            if(storey%10>5)
            {
                answer+=(10-storey%10);
                storey=storey/10;
                storey++;
            }
            else if(storey%10==5&&(storey%100/10)<5){
                answer+=5;
                storey=storey/10;
            }
            else if(storey%10==5&&(storey%100/10)>=5){
                answer+=5;
                storey=storey/10;
                storey++;
            }
            else if(storey%10<5){
                answer+=storey%10;
                storey=storey/10;
            }
        }
        return answer;
    }
}
반응형