June 2024:Rest Time
01
Source of the question
Luogu NetworkB4000 , Xin’ao Open Class
Problem Solving Approach
02
1. Time Conversion:
Convert the start time’s hours, minutes, and seconds into total seconds. Then add the study seconds <span><span>k</span></span>, resulting in the total seconds for the rest time.
2. Time Restoration:
Convert the total seconds back into hours, minutes, and seconds format, paying attention to how many cycles of hours, minutes, and seconds are involved; the correct cycle count is essential./ and % are classic methods for handling cycle problems.
3. Applicable Scenarios:
According to the problem’s data range, <span><span>36000</span></span> is exactly 10 hours, 12 hours 59 minutes 59 seconds, and at most it can reach 22 hours 59 minutes 59 seconds, which does not exceed 24 hours in a day.
Time difference problems within 24 hours of a day, converting time into relative<span><span>midnight</span></span> as the smallest unit of the problem.
Reference Solution
03
#include <bits/stdc++.h>using namespace std;
int main(){ int h,m,s,k; cin >> h >> m >> s >> k; // Convert to the smallest unit of the problem int tot = h * 3600 + m * 60 + s + k; // Get hours from seconds, remaining seconds less than an hour h = tot / 3600, tot %= 3600; // Get minutes from seconds, remaining seconds less than a minute m = tot / 60, tot %= 60; s = tot; cout << h << " " << m << " " << s << endl; return 0;}
Welcome to pay attention to the public account, to learn and progress together