Sunday, August 6, 2017

UVa problem solution 573 - The Snail

problem link:


Discuss: this is just simple logic problem.just continue a while loop.and check weather it is greater then the height or less then zero. if if not then decrease fatiage factor from every day climbing then increase day.   Be aware of using floating point.


try yourself before see the code


#include<bits/stdc++.h>
using namespace std;
int main()
{
double i,j,ud,uf;
 double u,h,f,d,day;
    double p;
    while(cin >>h)
    {
        day=0;
        cin >>u>>d>>f;
        if(h==0)
            break;
            uf=0.0;
            p=u;
            p=(float)p*(float)f/100.0;
            while(1)
            {
                day++;
                if(u>0)
                uf+=u;
                u-=p;
            if(uf>h)
                break;
             uf-=d;
            if(uf<0)
                break;

            }
            if(uf>0)
        printf("success on day %.0lf\n",day);
        else
            printf("failure on day %.0lf\n",day);
    }
    return 0;
}


No comments:

Post a Comment