当前位置:网站首页>Time display of the 12th Blue Bridge Cup
Time display of the 12th Blue Bridge Cup
2022-06-13 05:00:00 【Clown clown clown】
Examination site : simulation .
For time , Common methods are modulo and division .
Common formula :
hour = time / 3600
min = time % 3600 / 60
sec = time % 3600 % 60
notes : Understanding of modular operation , Equivalent to filtering out unwanted seconds .
for instance min = time % 3600 / 60; It is equivalent to asking for the number of minutes , Filter out the hours that belong to ( subtract ), Then divide the remaining seconds by 60, Get the minutes .
Ideas :
This problem is a little distorted . Since there is no need to display year, month and day , Therefore, the number of seconds given should be filtered out first . namely time % (24 * 60 * 60)
And a little bit more , It's not the number of seconds , It's milliseconds , So first divide by 1000 Count seconds , Then carry out a series of operations .
Code :
#include <iostream>
using namespace std;
long long t;
int main()
{
cin >> t;
t /= 1000;// hold ms become s
t %= (24 * 60 * 60);// Filter out the seconds belonging to month, year and day
// Three formulas
int h = t / 3600;
int m = t % 3600 / 60;
int s = t % 3600 % 60;
printf("%02d:%02d:%02d", h, m, s);
}
notes : Don't cycle every second to find the final hour,minute,second. There will be a series of mistakes .
边栏推荐
- Bomb disposal cat
- Chapter 15 mechanism: Address Translation
- QT interface rendering style
- Clause 30: be familiar with the failure of perfect forwarding
- Section 2 - branch and loop statements
- Chapter 18 pagination: Introduction
- LeetCode第297场周赛(20220612)
- CMB's written test -- data analysis
- Section 5 - Operator details
- C language learning log 10.4
猜你喜欢
QT interface rendering style
Section 5 - Operator details
RTSP streaming using easydarwin+ffmpeg
使用EasyDarwin+FFmpeg实现rtsp推流
The differences between the four startup modes of activity and the applicable scenarios and the setting methods of the two startup modes
Robot pose description and coordinate transformation
Win8.1和Win10各自的优势
Spice story
Ruoyi cloud startup tutorial (hand-held graphics)
PostgreSQL Guide: Insider exploration (Chapter 7 heap tuples and index only scanning) - Notes
随机推荐
Explain the role of key attribute in V-for
Ruoyi cloud startup tutorial (hand-held graphics)
Converting MySQL data to PostgreSQL with Navicat
[leetcode]- sliding window
Trust programming - linked lists: use struct to implement linked lists, use heap to merge K ascending linked lists, and customize display
Clause 34: lambda is preferred over std:: bind
PostgreSQL Guide: inside exploration (Chapter 10 basic backup and point in time recovery) - Notes
The processing flow of thread pool depends on the core parameters
Force buckle 92 Reverse linked list II
Force buckle 25 A group of K flipped linked lists
Conception d'un système basé sur MVC avec javaswing JDBC
Chinese trumpet creeper
C language learning log 10.11
详解OpenCV的函数cv::add(),并附各种情况的示例代码和运行结果
[untitled]
135. distribute candy
What is the saturate operation in opencv
Mysql8.0.13 installation tutorial (with pictures)
Must know must know -c language keywords
Reductive elimination