656. Banknotes and Coins

656. Banknotes and Coins

Read a floating point number with two decimal places, which represents the monetary value.

After that, the value is decomposed into the sum of various banknotes and coins. The number of banknotes and coins of each denomination is not limited, and the number of banknotes and coins used is required to be as small as possible.

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

The denominations of the coins are 1,0.50, 0.25, 0.10, 0.05 and 0.01.

Input format

Enter a floating point number N.

Output format

Refer to the output sample to output the required quantity of banknotes and coins of each denomination.

data range

0≤N≤1000000.00

Input sample:

576.73

Sample output:

NOTAS:
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
MOEDAS:
1 moeda(s) de R$ 1.00
1 moeda(s) de R$ 0.50
0 moeda(s) de R$ 0.25
2 moeda(s) de R$ 0.10
0 moeda(s) de R$ 0.05
3 moeda(s) de R$ 0.01
//取余运算必须是两个整数
//总结分离小数部分与整数部分的方法



#include <cstdio>

int main()
{
	double n;
	int n1, n2;
	
	scanf("%lf", &n);
	n = (int)(n * 100);
	n1 = n / 100;
	n2 = n - n1 * 100;  //注意这里是减去n1 * 100
	
	printf("NOTAS:\n");
	printf("%d nota(s) de R$ 100.00\n", n1 / 100);
	n1 = n1 % 100;
	printf("%d nota(s) de R$ 50.00\n", n1 / 50);
	n1 = n1 % 50;
	printf("%d nota(s) de R$ 20.00\n", n1 / 20);
	n1 = n1 % 20;
	printf("%d nota(s) de R$ 10.00\n", n1 / 10);
	n1 = n1 % 10;
	printf("%d nota(s) de R$ 5.00\n", n1 / 5);
	n1 = n1 % 5;
	printf("%d nota(s) de R$ 2.00\n", n1 / 2);
	
	printf("MOEDAS:\n");
	n1 = n1 % 2;
	printf("%d moeda(s) de R$ 1.00\n", n1);
	printf("%d moeda(s) de R$ 0.50\n", n2 / 50);
	n2 = n2 % 50;
	printf("%d moeda(s) de R$ 0.25\n", n2 / 25);
	n2 = n2 % 25;
	printf("%d moeda(s) de R$ 0.10\n", n2 / 10);
	n2 = n2 % 10;
	printf("%d moeda(s) de R$ 0.05\n", n2 / 5);
	n2 = n2 % 5;
	printf("%d moeda(s) de R$ 0.01\n", n2);
	
		
	return 0;
}

Guess you like

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