문제
팀의 막내인 철수는 아메리카노와 카페 라테만 판매하는 카페에서 팀원들의 커피를 사려고 합니다. 아메리카노와 카페 라테의 가격은 차가운 것과 뜨거운 것 상관없이 각각 4500, 5000원입니다. 각 팀원에게 마실 메뉴를 적어달라고 하였고, 그 중에서 메뉴만 적은 팀원의 것은 차가운 것으로 통일하고 "아무거나"를 적은 팀원의 것은 차가운 아메리카노로 통일하기로 하였습니다.
각 직원이 적은 메뉴가 문자열 배열 order로 주어질 때, 카페에서 결제하게 될 금액을 return 하는 solution 함수를 작성해주세요. order의 원소는 아래의 것들만 들어오고, 각각의 의미는 다음과 같습니다.
func solution(order []string) int {
// 아메리카노 가격 총 합 변수 선언
var a int
// 라테 가격 총 합 변수 선언
var c int
// order에서 메뉴 꺼내기
for _, o := range order {
// order에서 값을 꺼낸 o에서 anything 또는 iceamericano 또는 americanoice 또는 americano 또는 hotamericano 또는 americanohot 일 때
if o == "anything" || o == "americanoice" || o == "iceamericano" || o == "americano" || o == "hotamericano" || o == "americanohot" {
// 변수 a에 + 4500
a += 4500
}else {
// 그 외(latte일때) c에 + 5000
c += 5000
}
}
// 아메리카노와 카페라떼 총 합
return a + c
}
func solution(order []string) int {
result := 0
var c byte
for _, v := range order {
c = v[3]
if c == 'a' || c == 'r' || c == 't' {
result += 4500
}
if c == 'c' || c == 'e' {
result += 5000
}
}
return result
}
iceamericano
americanoice
hotamericano
americanohot
americano
anything
icecafelatte
cafelatteice
hotcafelatte
cafelattehot
cafelatte