货币系统(简单版)
发布时间
阅读量:
阅读量
题目描述
现行的人民币的货币系统为1元、5元、10元、20元、50元、100元(纸币)。
现在给定目标钱数n,请问最少需要多少张纸币可以表示出n元?
输入格式
一行,1个整数n,表示目标钱数。
输出格式
一行,1个整数,表示最小使用的纸币数。
样例输入
36
样例输出
4
问题提示
n<=20000
代码如下:
#include<bits/stdc++.h>
using namespace std;
int a[6] = {1,5,10,20,50,100};
int main()
{
int n,ans=0;
cin>>n;
for(int i=5;i>=0;i--)
{
ans+=n/a[i];
n%=a[i];
}
cout<<ans;
return 0;
}
AI写代码
全部评论 (0)
还没有任何评论哟~
