“This is the 11th day of my participation in the First Challenge 2022. For details: First Challenge 2022”

I. Problem description

Xiao LAN is going to cooperate with his friends to develop a time display website.

On the server, the friend has retrieved the current time as an integer number of milliseconds from 00:00:00, November 11, 1970 to the current moment.

Now, Blue will display the time on the client. Blue do not display the day, month, only need to display the hour, minute and second, ms do not display, directly off.

Given a time expressed as an integer, print the corresponding hour and minute.

Two, the title requirements

inspection

1. Time conversion, mathematical ideas 2. It is recommended to use 10~15minCopy the code

The input describing

The input line contains an integer representing the time.

Output description

Output time minute second Indicates the current time in the format of HH:MM:SS, where HH indicates the hour and the value is 0 to 23, MM indicates the minute and the value is 0 to 59, and SS indicates the second and the value is 0 to 59. If the hour, minute and second are less than two digits, 0 will be added.

Third, problem analysis

Unlike the date problem, which requires you to consider whether February has 28 or 29 days in a leap year, you just need to convert the number of milliseconds into seconds, with 1s=1000ms (don’t get me wrong, at first I thought 1s was equal to 60ms, but ended up counting half the time).

Finally, directly solve the number of seconds divided by 3600 and then take the module, the number of minutes divided by 60 and then take the module, the number of seconds directly take the module, the output results should pay attention to the complement, you can first look at the related knowledge points in the extension part.

expand

  • If the hour, minute, or second is less than two digits, you can use %02d. If the hour, minute, or second is less than two digits, you can use %02d
  • %d is an int common storage, %2d is 2 in width, the output is right-aligned, if the data bit is less than 2, the left side of the blank
  • Millisecond storage outside the int range, take long long int storage

Four, coding implementation

#include <iostream>
using namespace std;
long long int sum; 
int main(a)
{
	cin>>sum;// Enter the number of milliseconds
	int i,s=0,f=0,m=0,n;/ / initialization
	n=sum/1000;// Convert to seconds
	s=(n/3600) %24;// When calculated
	f=(n/60) %60;// Calculate the score
	m=n%60;// Count the seconds
	printf("%02d:%02d:%02d",s,f,m);// Output the result
    return 0;
}
Copy the code

5. Output results

Test case 146800999

Test case 21618708103123