描述
假设某种纸币的面额分别有1、5、10、20、50、100.
输入
输入一个金额 N ( 1 <= N <= 10000 ).
输出
请计算这种纸币的金额 N 最少需要多少张纸币并输出 .
输入样例 1
175输出样例 1
4#include<iostream> using namespace std; int main(){ int n,a[6] = {100,50,20,10,5,1}; cin >> n; int cnt = 0,ans = 0; while(n != 0){ if(n >= a[cnt]){ n = n - a[cnt]; ans++; }else{ cnt++; } } cout << ans << endl; return 0; }
如果有帮助,不妨点个赞再走吧!
纸币(C++)
最新推荐文章于 2024-02-23 16:29:19 发布