SWEA/D2
[SWEA] 1970. 쉬운 거스름돈
둘기친구
2019. 5. 3. 13:32
https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV5PsIl6AXIDFAUq
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
www.swexpertacademy.com
풀이
화폐단위를 미리 배열에 넣어두고 차례대로 나눠주며 count를 해줬다.
import java.io.*; public class Solution { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); for(int tc=1; tc<=T; tc++) { int N = Integer.parseInt(br.readLine()); int[] count = new int[8]; int[] money = {50000, 10000, 5000, 1000, 500, 100, 50, 10}; for(int i=0; i<8; i++) { if(N >= money[i]) { //돈이 화폐단위보다 같거나 클때만 나눠준다. int cnt = N/money[i]; count[i] = cnt; N -= cnt*money[i]; } } System.out.println("#"+tc); for(int i=0; i<8; i++) { System.out.print(count[i]+" "); } System.out.println(); } } }