Advertisement
koteshkoeziche

Task

Oct 29th, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. Programming Fundamentals Mid Exam Retake 07 April 2020
  2. Problem 1. Counter Strike
  3. Write a program that keeps track of every won battle against an enemy. You will receive initial energy. Afterwards you will start receiving the distance you need to go to reach an enemy until the "End of battle" command is given, or until you run out of energy.
  4. The energy you need for reaching an enemy is equal to the distance you receive. Each time you reach an enemy, your energy is reduced. This is considered a successful battle (win). If you don't have enough energy to reach an the enemy, print:
  5. "Not enough energy! Game ends with {count} won battles and {energy} energy"
  6. and end the program.
  7. Every third won battle increases your energy with the value of your current count of won battles.
  8. Upon receiving the "End of battle" command, print the count of won battles in the following format:
  9. "Won battles: {count}. Energy left: {energy}"
  10. Input / Constraints
  11. • On the first line you will receive initial energy – an integer [1-10000].
  12. • On the next lines, you will be receiving distance of the enemy – an integer [1-10000]
  13. Output
  14. • The description contains the proper output messages for each case and the format in which they
  15. should be print.
  16. Examples
  17. Input Output Comments
  18. 100
  19. 10
  20. 10
  21. 10
  22. 1
  23. 2
  24. 3
  25. 73
  26. 10 Not enough energy! Game ends with 7 won battles and 0 energy Initial energy is 100. The first distance is 10, so we subtract 10 from 100 and we consider this a won battle. We are left with 90 energy. Next distance – 10, and 80 energy left.
  27. Next distance – 10, 3 won battles and 70 energy, but since we have 3 won battles, we increase the energy with the current count of won battle, in this case – 3 and it becomes 73.
  28. The last distance we receive – 10 is unreachalble since we have 0 energy, so we print the appropriate message and the program ends.
  29. 200
  30. 54
  31. 14
  32. 28
  33. 13
  34. End of battle Won battles: 4. Energy left: 94
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement