题目描述
小智去超市买东西,买了不超过一百块的东西。收银员想尽量用少的纸币来找钱。
纸币面额分为 5050 、 2020 、 1010 、 55 、 11 五种。请在知道要找多少钱 n 给小明的情况下,输出纸币数量最少的方案。
输入格式
本题有多组测试数据!
对于每组测试数据,输入一行一个整数 n,表示一个找给小明的钱数。
输出格式
对于每种数量不为 00 的纸币,输出他们的面值 ×× 数量,再加起来输出,具体格式参见样例。
样例
输入数据#1
25
32
输出数据#1
20*1+5*1
20*1+10*1+1*2
数据范围
1≤991≤n≤99
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,t;
while(cin>>n)
{
if(n>=50)
{
cout<<"50*1";
n-=50;
if(n>0)
{
cout<<"+";
}
}
if(n>=20)
{
t=n/20;
cout<<"20*"<<t;
n-=20*t;
if(n>0)
{
cout<<"+";
}
}
if(n>=10)
{
cout<<"10*1";
n-=10;
if(n>0)
{
cout<<"+";
}
}
if(n>=5)
{
cout<<"5*1";
n-=5;
if(n>0)
{
cout<<"+";
}
}
if(n>=1)
{
cout<<"1*"<<n;
}
cout<<endl;
}
}