Skip to main content

Practice · 6 of 6

Clock Arithmetic

CHALLENGE
Difficulty: beginner+25 XP

**Description:** Given t (minutes, possibly negative) and k (a time-zone offset, 0 ≤ k ≤ 23) on one line t k. Total minutes = t + k·60. Print the hour of day in 24-hour form (a number 0..23). **Input:** One line: t k (−10^7 ≤ t ≤ 10^7, 0 ≤ k ≤ 23). **Output:** One integer 0..23. **Example:** 90 1 → (90 + 60)/60 = 2 → print 2; -30 0 → −30/60 = −1 hours → must wrap to 23. *Question:* which way does C++ integer division round for negatives? (((x % 24) + 24) % 24 is your friend.)

Back to lesson: Practice: Starter Set