Solution - UVa Problem 573 - The Snail



সল্যুশন্সঃ
#include<iostream>
using namespace std;

int main()
{
    double h,u,d,f;
    while(cin >> h >> u >> d >> f && h != 0)
    {
        int cnt = 0;
        double ht = 0.0;
        f=(f*u)/100;
        while(true)
        {
            cnt++;
            if(u>0)
            {
                ht+=u;
                u-=f;
            }
            if(ht>h)
                break;
            ht-=d;
            if(ht<0)
                break;
        }
        /*
        success on day 3
        failure on day 4
        */
        if(ht<0)
            cout << "failure on day " << cnt << endl;
        else if(ht>h)
            cout << "success on day " << cnt << endl;
    }
    return 0;
}

আলোচনাঃ
কোড কপি পেষ্ট না করে বুঝার চেষ্টা করুন। সতর্ক থাকরে হবে যেন height and fatigue factor নেগেটিভ না হয়। আর নতুন height যখন ই ইনপুট height এর চেয়ে বেশি হবে লুপ স্টপ করে দিতে হবে।

Comments

Popular posts from this blog

Solution - Codeforces Problem 327B - Hungry Sequence

Solution - Timus Problem 1293. Eniya

Solution - Timus Problem 1409. Two Gangsters