Uva 573 Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{
    double h, u, d, l;
    while(cin >> h >> u >> d >> l)
    {
        if(h == 0)
            break;
        double c, dis, t, nt;
        c = dis = t = nt = 0;
        int j = 0, f = 0, k = 1;
        while(t <= h && c >= 0)
        {
            dis = u - ((double)j*u*(l/100));
            if(dis >= 0)
                t = c + dis;
            else
                t = c;
            if(t > h)
            {
                break;
            }
            if(t < 0)
            {
                f = 1;
                break;
            }
            c = t - d;
            if(c < 0)
            {
                f = 1;
                break;
            }
            k++;
            j++;
        }
        if(f == 1)
            cout << "failure on day " << k << endl;
        else
            cout << "success on day " << k << endl;
    }
    return 0;
}

Comments