fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. for( ; ;) {
  7. int h, u, d,f;
  8. scanf("%d%d%d%d", &h,&u,&d,&f);
  9. if(h==0){
  10. break;
  11. }
  12. int day=1;
  13. double totalH=0, F = (u*f)/100.0;
  14. for(; ;){
  15. totalH += u;
  16. if(u>0){
  17. u -= F;
  18. cout<< u<<"u ";
  19. }
  20. if(totalH>h){
  21. break;
  22. }
  23. totalH-=d;
  24. cout<< totalH<<"tth ";
  25. if(totalH<0){
  26. break;
  27. }
  28. day++;
  29. cout<< day<<" d\n";
  30. }
  31.  
  32. if(totalH<0){
  33. printf("failure on day %d\n", day);
  34. } else{
  35. printf("success on day %d\n", day);
  36. }
  37.  
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0s 16064KB
stdin
6 3 1 10
0 0 0 0
stdout
2u 2tth 2 d
1u 3tth 3 d
0u 3tth 4 d
2tth 5 d
1tth 6 d
0tth 7 d
-1tth failure on day 7