본문 바로가기
코딩테스트/LV. 0

LV. 0 :: 옷가게 할인 받기

by KUROMI98 2023. 1. 20.

https://school.programmers.co.kr/learn/courses/30/lessons/120818

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

function solution(price) 
{
    var answer = 0;
    if (price < 100000) {answer = price;}
    else if  (price >= 100000 && price < 300000) {answer = price * 0.95;}
    else if (price >= 300000 && price < 500000) {answer = price * 0.9;}
    else if (price >= 500000) {answer = price * 0.8;}
    return Math.floor(answer);
}

+) 230510

const solution = (price) => {
    let answer = 0;
    if (price<100000){ answer = price }
    else if (price >=100000 && price<300000){ answer = price*0.95}
    else if (price >=300000 && price<500000){ answer = price*0.90}
    else if (price >=500000 ){ answer = price*0.80}
    return Math.floor(answer);
}

230525 python

import math

def solution(price):
    
    answer = 0
    
    if price<100000:
        answer = price
        
    elif price >=100000 and price<300000:
        answer = price*0.95
        
    elif price >=300000 and price<500000:
        answer = price*0.90
        
    elif price >=500000:
        answer = price*0.80
        
    return math.floor(answer)

'코딩테스트 > LV. 0' 카테고리의 다른 글

LV. 0 :: 점의 위치 구하기  (0) 2023.01.20
LV. 0 :: 각도기  (0) 2023.01.20
LV. 0 :: 배열 두 배 만들기  (0) 2023.01.20
LV. 0 :: 짝수는 싫어요  (0) 2023.01.20
LV. 0 :: 짝수 홀수 개수  (0) 2023.01.20

댓글