study_IT/알고리즘 노트
[programmers] 코딩테스트 입문 Day 5
맛집줘
2023. 10. 17. 21:57
728x90
반응형
1. 옷가게 할인받기
class Solution {
public 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));
} else {
answer = price;
}
return answer;
}
}
2. 아이스 아메리카노
class Solution {
public int[] solution(int money) {
int[] result = new int[2];
result[0] = money / 5500;
result[1] = money % 5500;
return result;
}
}
3. 나이 출력
class Solution {
public int solution(int age) {
return (2022 - age) + 1;
}
}
4. 배열 뒤집기
class Solution {
public int[] solution(int[] num_list) {
int[] answer = new int[num_list.length];
for(int i=0; i<num_list.length; i++){
answer[i] = num_list[num_list.length - 1 - i];
}
return answer;
}
}
728x90
반응형