알고리즘/Array
치킨 쿠폰
e-pd
2021. 7. 13. 19:54
https://www.acmicpc.net/problem/1673
1673번: 치킨 쿠폰
강민이는 치킨 한 마리를 주문할 수 있는 치킨 쿠폰을 n장 가지고 있다. 이 치킨집에서는 치킨을 한 마리 주문할 때마다 도장을 하나씩 찍어 주는데, 도장을 k개 모으면 치킨 쿠폰 한 장으로 교환
www.acmicpc.net
import java.util.*;
public class Main {
private static int N = 0;
private static int K = 0;
private static int RESULT = 0;
private static int STAMP = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
if(!sc.hasNextLine()) {
return;
}
String[] nums = sc.nextLine().split(" ");
N = Integer.parseInt(nums[0]);
K = Integer.parseInt(nums[1]);
STAMP = 0;
RESULT = 0;
recursive();
System.out.println(RESULT);
}
}
public static void recursive() {
if (N > 0) {
RESULT += N;
STAMP += N;
N = 0;
}
if (STAMP > 0) {
N += STAMP / K;
STAMP = STAMP % K;
}
if (N > 0) {
recursive();
}
}
}
처음 결과와 도장에는 N만큼 더해준다.