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;
}
///**********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