1 条题解
-
0
【例13.2】 电子表
解题思路
小时为秒数除 3600,分钟为除 60 后模 60,秒为模 60。各部分按两位补零输出。
正确性说明
整除与余数按 3600、60 的位权分解时长,组合为电子表时分秒。
易错点
不足两位补前导零,分隔符为冒号。
复杂度
本题输入规模固定,时间 O(1),额外空间 O(1)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; cout << setfill('0') << setw(2) << t / 3600 << ":" << setw(2) << t / 60 % 60 << ":" << setw(2) << t % 60 << "\n"; return 0; }
- 1