[Programmers] #120830 - 양꼬치 [Java][C++][Python]
[Programmers] #120830 - 양꼬치 [Java][C++][Python]
1. 아이디어
양꼬치 $n$인분과 음료수 $k$개를 먹었을 때 내야 할 금액을 구하는 문제다. 10인분마다 음료수가 하나 서비스로 나오므로 서비스 음료수는 $\lfloor n / 10 \rfloor$개이고, 먹은 음료수 $k$개에 이 서비스분이 포함되어 있으므로 값을 치르는 음료수는 $k - \lfloor n / 10 \rfloor$개다. 따라서 금액은 $12{,}000n + 2{,}000(k - \lfloor n / 10 \rfloor)$원이다.
2. 코드
풀이 [Java][C++][Python]
1
2
3
4
5
class Solution {
public int solution(int n, int k) {
return n * 12000 + (k - n / 10) * 2000;
}
}
1
2
3
4
5
6
#include <bits/stdc++.h>
using namespace std;
int solution(int n, int k) {
return n * 12000 + (k - n / 10) * 2000;
}
1
2
def solution(n, k):
return n * 12000 + (k - n // 10) * 2000
This post is licensed under CC BY 4.0 by the author.