SWEA 1970 쉬운 거스름돈

1 개요[ | ]

SWEA 1970 쉬운 거스름돈

2 C++[ | ]

#include <iostream>
using namespace std;
int T, N;
int main() {
	int units[8] = {50000,10000,5000,1000,500,100,50,10};
	scanf("%d", &T);
	for(int tc=1; tc<=T; tc++) {
		scanf("%d", &N);
		printf("#%d\n", tc);
		for(int i=0; i<8; i++) {
			int ea = N/units[i];
			N %= units[i];
			printf("%d ", ea);
		}
		printf("\n");
	}
}

3 Java[ | ]

import java.util.Scanner;
public class Solution {
    public static void main(String args[]) {
        final int units[] = {50000,10000,5000,1000,500,100,50,10};
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int t=1; t<=T; t++) {
            int n = sc.nextInt();
            System.out.format("#%d\n", t);
            for(int u: units) {
                System.out.format("%d ", n/u );
                n %= u;
            }
            System.out.format("\n");
        }
    }
}

4 Python[ | ]

T = int(input())
for t in range(1, T+1):
    N = int(input())
    KRW_list = [50000, 10000, 5000, 1000, 500, 100, 50, 10]
    KRW_dict = dict.fromkeys(KRW_list, 0)
    # KRW_dict = {50000: 0, 10000: 0, 5000: 0, 1000: 0, 500: 0, 100: 0, 50: 0, 10: 0}

    for i in KRW_list:
        KRW_dict[i] += N // i
        N %= i
    
    print(f'#{t}')
    for i in KRW_list:
        print(KRW_dict[i], end=' ')
    print()

# github.com/wansang93/Algorithm
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}