1259: 找零钱
时间限制: 1 Sec 内存限制: 128 MB
题目描述
小智去超市买东西,买了不超过一百块的东西。收银员想尽量用少的纸币来找钱。
纸币面额分为50 20 10 5 1 五种。请在知道要找多少钱n给小明的情况下,输出纸币数量最少的方案。 1<=n<=99;输入
有多组数据 1<=n<=99;
输出
对于每种数量不为0的纸币,输出他们的面值*数量,再加起来输出
样例输入
25 32
样例输出
20*1+5*1 20*1+10*1+1*2
#include <iostream>
using namespace std;
int main()
{
int n,i;
int m[5]={50,20,10,5,1};
while(cin>>n){
for(i=0;i<5;i++){
if(n>=m[i]){
cout<<m[i]<<"*"<<n/m[i];
n%=m[i];
if(n>0) cout<<"+";
}
}
cout<<endl;
}
return 0;
}