653.钞票
在这个问题中,你需要读取一个整数值并将其分解为多张钞票的和,每种面值的钞票可以使用多张,并要求所用的钞票数量尽可能少。
请你输出读取值和钞票清单。
钞票的可能面值有 100,50,20,10,5,2,1100,50,20,10,5,2,1。
输入格式
输入一个整数 NN。
输出格式
参照输出样例,输出读取数值以及每种面值的钞票的需求数量。
数据范围
0<N<10000000<N<1000000
输入样例:
576
输出样例:
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
题解:
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner scanner = new Scanner(System.in);
int s = scanner.nextInt();
System.out.println(s);
/*
int list[] = new int[7];
if (s / 100 != 0) {
list[0] = (s/100);
s = s % 100;
}
if (s / 50 != 0) {
list[1] =(s / 50);
s = s % 50;
}
if (s / 20 != 0) {
list[2] = (s / 20);
s %= 20;
}
if (s / 10 != 0) {
list[3]=(s / 10);
s %= 10;
}
if (s / 5 != 0) {
list[4]=(s / 5);
s %= 5;
}
if (s / 2 != 0) {
list[5]=(s / 2);
s %= 2;
}
if (s / 1 != 0) {
list[6]=(s / 1);
s %= 1;
}
*/
int[] money = {100, 50, 20, 10 ,5, 2, 1};
for (int i = 0; i < money.length; i++) {
System.out.printf("%d nota(s) de R$ %d,00\n", (s / money[i]), money[i]);
s %= money[i];
}
}
}
评论区