본문 바로가기
CodingTest

코딩테스트 입문 - Day 5

by Jiwon_Loopy 2025. 4. 12.
반응형

옷가게 할인 받기


class Solution {
    public static int solution(int price) {
        int answer = 0;
        
        if(price >= 100000 && price < 300000){
            answer = (int) (price - (price * 0.05));
        }
        else if(price >= 300000 && price < 500000){
            answer = (int) (price - (price * 0.1));
        }
        else if(price >= 500000){
            answer = (int) (price - (price * 0.2));
            System.out.println(answer);
        }else {
        	answer = price;
        }
        return answer;
    }
}

아이스 아메리카노


class Solution {
    public int[] solution(int money) {
        int[] answer = new int[2];
        answer[0] = money / 5500;
        answer[1] = money % 5500;
        return answer;
    }
}

나이 출력


class Solution {
    public int solution(int age) {
        return 2022 - age + 1;
    }
}

배열 뒤집기


class Solution {
    public int[] solution(int[] num_list) {
        int[] answer = new int[num_list.length];
        for(int i = num_list.length -1; i >=0; i--){
            answer[i] = num_list[num_list.length - i - 1];
        }
        return answer;
    }
}
728x90
반응형