[ create a new paste ] login | about

Link: http://codepad.org/zixLnCLa    [ raw code | fork ]

iamyeasin - C++, pasted on May 30:
#include<bits/stdc++.h>
#define sf scanf
#define pf printf

using namespace std;

int main()
{
//    freopen("input.txt","rt",stdin);
//    freopen("output.txt","wt",stdout);

    // H = Height of the wall
    // U = Snail climb during day
    // D = Slides down at night
    // F = Fatigue factor

    double h,u,d,f,has,in,hac,dc;
    long day=0;

    while(sf("%lf %lf %lf %lf",&h,&u,&d,&f), (h || u || d || f))
    {
        in = 0.0;
        dc = u;
        hac = dc+in;
        has = hac - d;
        day = 1;
        double fat = (f*u)/100.00;
//        cout << fat << endl;

        while(1)
        {
//            cout << day << " " << in << " " << dc << " " << hac << " " << has << " " << endl;

            if(hac > h)
            {
                pf("success on day %ld\n",day);
                break;
            }
            else if(dc < 0.00)
            {
                dc = 0.0;
            }
            else if(has < 0.00)
            {
                pf("failure on day %ld\n",day);
                break;
            }
            else
            {
                ++day;
                in = has;
                dc = dc-fat;
                hac = in + dc;
                has = hac - d;
            }

        }

    }




    return 0;
}


Create a new paste based on this one


Comments: