蓝桥 时间显示
题目描述
小蓝要和朋友合作开发一个时间显示的网站。
在服务器上,朋友已经获取了当前的时间,用一个整数表示,值为从 19701970 年 11 月 11 日 00:00:0000:00:00 到当前时刻经过的毫秒数。
现在,小蓝要在客户端显示出这个时间。小蓝不用显示出年月日,只需要显示出时分秒即可,毫秒也不用显示,直接舍去即可。
给定一个用整数表示的时间,请将这个时间对应的时分秒输出。
输入描述
输入一行包含一个整数,表示时间。
输出描述
输出时分秒表示的当前时间,格式形如 HH:MM:SS
,其中 HH
表示时,值为 00 到 2323,MM
表示分,值为 00 到 5959,SS
表示秒,值为 00 到 5959。时、分、秒 不足两位时补前导 00。
输入输出样例
示例 1
输入
46800999

输出
13:00:00
示例 2
输入
1618708103123

输出
01:08:23

评测用例规模与约定
对于所有评测用例,给定的时间为不超过 10^{18}1018 的正整数。
#include<iostream> #include<iomanip> using namespace std; int main() { long long t; cin >> t; t /= 1000;//注意是毫秒 int h = t / 3600 % 24; int m = t / 60 % 60; int s = t % 60; cout << setw(2) << setfill('0') << h << ':';//输出方式 cout << setw(2) << setfill('0') << m << ':';//setw只对后面一个有用 cout << setw(2) << setfill('0') << s; return 0; }
#include<iostream> #include<iomanip> using namespace std; int main() { long long t; cin >> t; t /= 1000;//注意是毫秒 int h = t / 3600 % 24; int m = t / 60 % 60; int s = t % 60; cout << setw(2) << setfill('0') << h << ':';//输出方式 cout << setw(2) << setfill('0') << m << ':';//setw只对后面一个有用 cout << setw(2) << setfill('0') << s; return 0; }