Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Task 6. High jump
- Bulgarian track and field athlete Tihomir Ivanov begins training for the upcoming European Indoor Athletics Championships in Glasgow, Scotland.
- Your job is to write software to keep track of your progress and whether it has achieved the desired results. At the beginning, the program gets the desired height of the bar from Tihomir, he begins his training by setting the bar at a height of 30 cm below the target. For each height he is entitled to 3 jumps, and in order for one jump to be successful, he must be above the height of the bar. Upon successful jump (above the bar), its height rises by 5 centimeters. With three unsuccessful jumps at the same height, the training ends with failure. When reaching the desired height and successfully jumping over, the training ends with success.
- Sign in
- The input is a series of integers in the range [100… 300]:
- • The first line reads the desired height by Tihomir Ivanov in centimeters
- • The height of Ivanov's jump is read out on each successive line until the end of the program
- Exit
- One row must be printed on the console:
- • If Tihomir fails to reach the desired height:
- o "Tihomir failed at {height at the time of failure} cm after {number of jumps since start of training} jumps."
- • If Tihomir manages to overcome the height:
- o "Tihomir succeeded, he jumped over {jumps last jump} cm after {number of jumps for the whole workout}."
- using System;
- namespace _06.HighJump
- {
- class HighJump
- {
- static void Main(string[] args)
- {
- int height = int.Parse(Console.ReadLine());
- int startheight = height - 30;
- int numJumps = 0;
- int fail = 0;
- while (true)
- {
- int jump = int.Parse(Console.ReadLine());
- numJumps++;
- if (startheight < jump)
- {
- startheight += 5;
- fail = 0;
- }
- else
- {
- fail++;
- }
- if (fail == 3)
- {
- break;
- }
- else if (startheight >= height)
- {
- break;
- }
- }
- Console.WriteLine($"Tihomir failed at {startheight}cm after {numJumps} jumps.");
- Console.WriteLine($"Tihomir succeeded, he jumped over {startheight}cm after {numJumps} jumps.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment