AcWing 656. 钞票和硬币 - Java
原题链接
中等
作者:
KYCygni
,
2021-03-07 03:37:45
,
所有人可见
,
阅读 341
Java 代码
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
double money = cin.nextDouble();
money *= 100;
int m = (int)money;
int[] bills = {10000, 5000, 2000, 1000, 500, 200};
int[] coins = {100, 50, 25, 10, 5, 1};
System.out.println("NOTAS:");
for (int i = 0; i < bills.length; i ++)
{
System.out.println( m / bills[i] + " nota(s) de R$ " + String.format("%.2f", bills[i] / 100.0 ) );
m = m % bills[i];
}
System.out.println("MOEDAS:");
for (int j = 0; j < coins.length; j ++)
{
System.out.println( m / coins[j] + " moeda(s) de R$ " + String.format("%.2f", coins[j] / 100.0) );
m = m % coins[j];
}
}
}