Pages

Saturday, June 2, 2012

573 - The Snail



//
// main.cpp
// The Snail
//
// Created by Panks on 23/05/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include <cmath>
using namespace std;
int main (int argc, const char * argv[])
{


double h, u, d;
int f;
cin>>h>>u>>d>>f;

while (h!=0) {
double tmp=0;
int count=0;
double df=u*f/100.0;
while (1) {
tmp=tmp+u;
count++;
if(tmp>h){
cout<<"success on day "<<count<<endl;
break;
}
tmp-=d;
if(tmp<0&&count>0){
cout<<"failure on day "<<count<<endl;
break;
}
u=u-df;
if (u<0) {
u=0;
}
}

cin>>h>>u>>d>>f;
}

return 0;
}


No comments:

Post a Comment