Guest User

Untitled

a guest
Apr 4th, 2022
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System;
  2.  
  3. namespace P06.HighJump
  4. {
  5.     class HighJump
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             const int INITIAL_HIGH_LESS_THAN_GOAL_IN_CM = 30;
  10.             const int INCREASE_HIGH_FOR_A_SUCCESSFUL_JUMP_IN_CM = 5;
  11.             const int LIMIT_TIMES_FOR_UNSUCCESSFUL_JUMPS = 3;
  12.  
  13.             int goal = int.Parse(Console.ReadLine());
  14.             int currentJump = int.Parse(Console.ReadLine());
  15.  
  16.             int start = goal - INITIAL_HIGH_LESS_THAN_GOAL_IN_CM;
  17.             int countOfTotalJumps = 0;
  18.             int countOfUnsuccessfulJumps = 0;
  19.  
  20.             while (start <= goal)
  21.             {
  22.                 while (currentJump <= start)
  23.                 {
  24.                     countOfTotalJumps++;
  25.  
  26.                     countOfUnsuccessfulJumps++;
  27.  
  28.                     if (countOfUnsuccessfulJumps == LIMIT_TIMES_FOR_UNSUCCESSFUL_JUMPS)
  29.                     {
  30.                         Console.WriteLine($"Tihomir failed at {start}cm after {countOfTotalJumps} jumps.");
  31.                         return;
  32.                     }
  33.  
  34.                     currentJump = int.Parse(Console.ReadLine());
  35.                 }
  36.  
  37.                 if (currentJump > goal)
  38.                 {
  39.                     break;
  40.                 }
  41.  
  42.                 countOfTotalJumps++;
  43.  
  44.                 countOfUnsuccessfulJumps = 0;
  45.  
  46.                 start += INCREASE_HIGH_FOR_A_SUCCESSFUL_JUMP_IN_CM;
  47.  
  48.                 currentJump = int.Parse(Console.ReadLine());
  49.             }
  50.  
  51.             countOfTotalJumps++;
  52.  
  53.             Console.WriteLine($"Tihomir succeeded, he jumped over {goal}cm after {countOfTotalJumps} jumps.");
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment