Health Bar

5

1 votes
Medium
Problem

Lulu is creating a health bar for a game. The problem is, she can't quite get it right. Help her!

She wants a player's health bar to be represented by 10 equal signs enclosed in square brackets, as in: [==========]. Each equal sign represents 10% of the player's health.

Lulu wants you to create a program that would simulate the stream of changes of a health bar after a series of damages and regenerations have been applied.

INPUT FORMAT

Input consists of an arbitrary pairs of input in the format cn, where c could either be a plus sign (+) to indicate regeneration or a minus sign (-) to indicate damage, and n is an integer indicating the percentage of regeneration or damage.

OUTPUT FORMAT

For each input, display the health bar depicting its current state after the regeneration or damage has been applied followed by the percentage value.

If regenerating results to a health bar more than 100%, represent it as 100% (e.g. [==========] 100%).

If being damaged results to the health being equal to 0 or going below 0, represent it as an empty health bar - 10 spaces enclosed in square brackets - with the string "DEAD" without the quotation marks (e.g. [          ] DEAD).

If applying the regeration or damage results to a value that is not a multiple of 10, represent in the health bar its corresponding rounded down value but display the actual percentage (e.g. applying -5 to a 100% health bar results to 95%. The output should look like: [========= ] 95%).

The health bar and the corresponding percentage value/string "DEAD" should be separated by a single space.

CONSTRAINTS

c could be + or -
1 <= n <= 100

Sample Input
-5
+25
+10
-30
+18
Sample Output
[========= ] 95%
[==========] 100%
[==========] 100%
[=======   ] 70%
[========  ] 88%
Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?