58. Parking Fee Calculation
Difficulty: easy · Math, String
Problem
A parking lot charges by the hour using tiered rates: - each of the first 2 hours: ₹100 - each of hours 3 to 5: ₹50 - each hour beyond 5: ₹20 For example, 6 hours cost `2*100 + 3*50 + 1*20 = 370`. The input is the number of hours as typed by the user. If it is not a non-negative whole number (for example `SIX`, `2.5` or `-3`), print `ERROR`.
Input
A single line containing the hours as text.
Output
Print the total fee as an integer, or `ERROR`.
Example 1
Input: 2 Output: 200
Explanation: Both hours are in the first tier: 2 * 100 = 200.
Example 2
Input: 6 Output: 370
Explanation: 2*100 + 3*50 + 1*20 = 370.
Example 3
Input: SIX Output: ERROR
Explanation: The input is not a number, so ERROR.
Constraints
- The line has 1 to 20 characters with no spaces - When valid, 0 <= hours <= 10^9
Solutions are judged against 3 sample and 10 hidden tests. Sign in to solve it · All problems