焦点速递!CF 996A - Hit the Lottery

时间:2023-06-24 09:35:39来源:哔哩哔哩

Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance?

艾伦有很多钱。 他在银行有 n 美元。 出于安全考虑,他想以现金的方式提取(我们这里不会透露原因)。 美元钞票的面额为 1、5、10、20、100。艾伦提取全部余额后最少可以收到多少张钞票?


【资料图】

------------------------------------------------------------

看来Allen的钱并不多啊。。。

其实就是取余,依次循环即可;;

下面是代码:

import java.util.Scanner;

public class A996 {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

sc.close();

int cnt=0;

int[]arr={100,20,10,5,1};

int i=0;

while(n>0&&i<5){

cnt+=n/arr[i];

n=n%arr[i];

i++;

}

System.out.println(cnt);

}

}

没错完全是凑字数的。不好意思。

关键词:
    ------分隔线----------------------------
    推荐阅读