UVA 573 The Snail Solution

Solve in C++:

///**********ALLAH IS ALMIGHTY************///
     ///AH Tonmoy
    ///Department of CSE,23rd batch
    ///Islamic University,Bangladesh

#include<iostream>
using namespace std;
int main()
{
    double h,u,d,f;
    while(cin >> h >> u >> d >> f && h != 0)
    {
        int i = 0;
        double ht = 0.0;
        f=(f*u)/100;
        while(1)
        {
            i++;
            if(u>0)
            {
                ht=ht+u;
                u=u-f;
            }
            if(ht>h)
                break;
            ht=ht-d;
            if(ht<0)
                break;
        }
        if(ht<0)
            cout << "failure on day " << i << endl;
        else if(ht>h)
            cout << "success on day " << i << endl;
    }
    return 0;
}

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.