배열뒤에서 부터 계산해주면 편하다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package greedy;
 
 
public class Main5585_거스름돈 {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int change = Integer.parseInt(br.readLine());
        int[] value = { 151050100500 };
 
        int money = 1000 - change;
        int count = 0;
 
        for (int i = value.length - 1; i >= 0; i--) {
            int num = money / value[i];
            money = money - (value[i] * num);
            count += num;
            if(money ==0break;
        }
        System.out.println(count);
 
    }//end of main
}//end of class
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs

+ Recent posts