653. Banknotes

653. Banknotes

In this problem, you need to read an integer value and decompose it into the sum of multiple banknotes. Multiple banknotes of each denomination can be used, and the number of banknotes used is as small as possible.

Please output the read value and bill list.

The possible denominations of banknotes are 100,50,20,10,5,2,1.

Input format

Enter an integer N.

Output format

Refer to the output sample to output the read value and the required number of banknotes of each denomination.

data range

0<N<1000000

Input sample:

576

Sample output:

576
5 nota(s) de R$ 100,00
1 nota(s) de R$ 50,00
1 nota(s) de R$ 20,00
0 nota(s) de R$ 10,00
1 nota(s) de R$ 5,00
0 nota(s) de R$ 2,00
1 nota(s) de R$ 1,00
/* 这题因为最小面值是1,所以直接从大到小除就完事儿了,
或者不用写这么长,直接每次令 n = n % 上一个面值即可
最小不是1就直接用循环*/



#include <cstdio>
#include <cmath>

int main()
{
	int n;
	scanf("%d", &n);
	printf("%d\n", n);
	printf("%d nota(s) de R$ 100,00\n", n / 100);
	printf("%d nota(s) de R$ 50,00\n", n % 100 / 50); 
	printf("%d nota(s) de R$ 20,00\n", n % 100 % 50 / 20);
	printf("%d nota(s) de R$ 10,00\n", n % 100 % 50 % 20 / 10);
	printf("%d nota(s) de R$ 5,00\n", n % 100 % 50 % 20 % 10 / 5);
	printf("%d nota(s) de R$ 2,00\n", n % 100 % 50 % 20 % 10 % 5 / 2);
	printf("%d nota(s) de R$ 1,00\n", n % 100 % 50 % 20 % 10 % 5 % 2);
	
	
	
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_42465670/article/details/114558482