Sunday 5 June 2016

Change (UVaLive 3004, Regionals 2004 >> South Pacific)

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive / spoj), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

#include<bits/stdc++.h>
using namespace std;

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 100000


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int tc, kk=1, n, notes[]={2000, 1000, 500, 200, 100, 50, 20, 10, 5}, cst, ofr, chg;
    double cost, offer;
    string s;
    char ch;
    while(cin>>cost>>offer)
    {
        cost+=.005, offer+=.005;
        cost*=100.0, offer*=100.0;
        cst=cost, ofr=offer;
        //cout<<offer<<" "<<cst<<endl;
        if(cst==0 && ofr==0) break;
        if(cst%5==1) cst-=1;
        else if(cst%5==2) cst-=2;
        else if(cst%5==3) cst+=2;
        else if(cst%5==4) cst+=1;

        if(cst>ofr) cout<<"Not enough money offered.\n";
        else if(cst==ofr) cout<<"Exact amount.\n";
        else
        {
            chg=ofr-cst;

            int space=0;
            for(int i=0;i<9;i++)
            {
                int cnt=0;
                while(chg>=notes[i])
                {
                    cnt++;
                    chg-=notes[i];
                }
                if(cnt)
                {
                    if(space) cout<<" ";
                    space=1;
                    if(i<5)
                        cout<<"$"<<notes[i]/100<<"*"<<cnt;
                    else
                        cout<<notes[i]<<"c*"<<cnt;
                }
            }
            cout<<"\n";
        }

    }
return 0;
}

No comments:

Post a Comment