Tip Total
Easy · rating 900 · Math, Implementation
A bill comes to bill cents and you want to leave a pct percent tip. Read the two space-separated integers bill and pct. Print the total to pay in cents, where the tip is bill × pct ÷ 100 rounded down to a whole cent.
Constraints: 0 ≤ bill ≤ 109, 0 ≤ pct ≤ 100
Editorial
Approach
The tip is bill × pct ÷ 100, and the problem asks for the whole-cent tip rounded down, so use integer (floor) division. The total is simply the bill plus that tip.
bill, pct = map(int, input().split())
tip = bill * pct // 100
print(bill + tip)Watch out
Compute bill * pct before dividing so the single rounding step happens on the product — dividing first would lose precision. In languages with 32-bit ints, use 64-bit to hold bill * pct.
Complexity
Time: O(1). Space: O(1).
Related problems
- Even Numbers Up To N — Easy
- Leap Year — Easy
- FizzBuzz — Easy
- Hex to Decimal — Easy
- Parking Fee — Easy
- Seconds to HH:MM:SS — Easy