人民币支付

描述

从键盘输入一指定金额(以元为单位,如345),然后输出支付该金额的各种面额的人民币数量,显示100元,50元,20元,10元,5元,1元各多少张,要求尽量使用大面额的钞票。

输入

一个小于1000的正整数。

输出

输出分行,每行显示一个整数,从上到下分别表示100元,50元,20元,10元,5元,1元人民币的张数

样例输入

735

样例输出

7
0
1
1
1
0
#include <iostream>

using namespace std;
typedef long long ll;
#define A 10+5
int judge (int );
int i,j=0;
int main()
{
    int n;
    cin>>n;
    int a=0,b=0,c=0,d=0,e=0;//100,50,20,10,5
    while(n>5)
    {
        if(judge(n)==3)
        {
            a=n/100;
            n%=100;
            }
        if(judge(n)==2)
        {
            if(n>=50)
            {
                n-=50;
                b++;
                }
            while (n>=20)
            {
                n-=20;
                c++;
                }
            if(n>=10)
            {
                n-=10;
                d++;
                }
        }
            if(n>=5)
            {
                n-=5;
                e++;
                }
            }
        cout<<a<<"\n"<<b<<"\n"<<c<<"\n"<<d<<"\n"<<e<<"\n"<<n<<endl;
        return 0;
        }


int judge (int n)
{
    int count=0;
    while(n)
    {
        count++;
        n/=10;
        }
    return count;
    }
发布了113 篇原创文章 · 获赞 2 · 访问量 1547

猜你喜欢

转载自blog.csdn.net/C_Dreamy/article/details/103785878