SWEA

[SWEA] 쉬운 거스름돈

itsnot4me 2024. 9. 30. 14:50

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5PsIl6AXIDFAUq&categoryId=AV5PsIl6AXIDFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=2

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

import java.util.Scanner;
import java.io.FileInputStream;


class Solution
{
	public static void main(String args[]) throws Exception
	{
		
		Scanner sc = new Scanner(System.in);
		int T;
		T=sc.nextInt();

		for(int test_case = 1; test_case <= T; test_case++)
		{
			int won = sc.nextInt();
            int omanwon = 0;
            int manwon = 0;
            int ochunwon =0;
            int chunwon =0;
            int obaekwon =0;
            int baekwon =0;
            int oshipwon =0;
            int shipwon =0;
            
            while(won>=50000){
                won -=50000;
                omanwon++;
            }
            while(won>=10000){
                won -=10000;
                manwon++;
            }
            while(won>=5000){
                won -=5000;
                ochunwon++;
            }
            while(won>=1000){
                won -=1000;
                chunwon++;
            }
            while(won>=500){
                won -=500;
                obaekwon++;
            }
            while(won>=100){
                won -=100;
                baekwon++;
            }
            while(won>=50){
                won -=50;
                oshipwon++;
            }
            while(won>=10){
                won -=10;
                shipwon++;
            }
            System.out.println("#" + test_case);
            System.out.println(omanwon  +" "+ manwon+" "+ochunwon+" "+chunwon+" "+obaekwon+" "+baekwon+" "+oshipwon+" "+shipwon);               
            
		}
	}
}

 

간단한 while 문 예제로 풀면 된다

'SWEA' 카테고리의 다른 글

[SWEA] 두 개의 숫자열  (0) 2024.10.04
[SWEA] 숫자를 정렬하자  (0) 2024.09.30
[SWEA] 스도쿠 검증  (0) 2024.09.30
[SWEA] 시각 덧셈  (0) 2024.09.27
[SWEA] 조교의 성적 매기기  (0) 2024.09.26