머쓱이네 옷가게는 10만 원 이상 사면 5%, 30만 원 이상 사면 10%, 50만 원 이상 사면 20%를 할인해줍니다.
구매한 옷의 가격 price가 주어질 때, 지불해야 할 금액을 return 하도록 solution 함수를 완성해보세요.
| price | result |
|---|---|
| 150,000 | 142,500 |
| 580,000 | 464,000 |
#include <string>
#include <vector>
using namespace std;
int solution(int price) {
int answer = 0;
if(price>=100000 && price <300000){
answer = price - (price * 0.05);
}
else if(price>=300000 && price<500000){
answer = price - (price * 0.1);
}
else if(price>=500000){
answer = price - (price * 0.2);
}
else{
answer = price;
}
return answer;
}
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int solution(int price) {
if (price>=500000) {
price *= 0.8;
} else if (price>=300000) {
price *= 0.9;
} else if (price>=100000) {
price *= 0.95;
}
return price;
}
둘 다 보기 좋은걸요! 알고리즘을 이해하고 있다는게 중요한 것 아닐까요?!!;ヾ(≧▽≦*)o