18 条题解
-
2
using namespace std; int main() { int a,x,y; cin >> a; x = a / 3600; a = a - (x * 3600); y = a / 60; a = a - (y * 60); cout << x << " " << y << " " << a; return 0; }` ``` --- (第一次写题解,代码可能并不是最简单的,请谅解) 解析: 1,定义变量用于获取秒数,储存小时与分钟。 2,将秒数除以3600以获取小时,并将秒数减去已经化为小时的部分。 3,将剩余秒数除以60以获取分钟,减去秒数内化为分钟的部分。 4,剩余秒数便是无法化为小时或分钟的,直接输出即可。 5,看到这了就点个赞吧👍
-
1
题解
思路
输入的是秒,也就是说,我们不用秒转换成秒,只要转换成小时和分钟就好了
Tip:小时和秒的进率是3600,分钟和秒的进率是60
偷懒简化输入的是一个整数,用一个变量装,最后让另一个变量(秒)等于它,那直接输入一个整数,用变量秒装它就行了,去掉一个变量
#include <iostream> using namespace std; int main() { int h, m, s; cin >> s; h = s / 3600; s -= 3600 * h; m = s / 60; s -= m * 60; cout << h << " " << m << " " << s << endl; return 0; }
-
1
解析
输入一个秒数n,将其转换为小时,分钟,秒的形式。
例如
3601
秒,应该转换为1 0 1
。设小时为h,分钟为m,秒钟为s,
易得,因为一小时等于3600秒
,因为为总的分钟数,再减去小时占去的部分,就是
,因为一分钟等于60秒。
题解
#include <iostream> using namespace std; int main() { int n; int h, m, s; cin >> n; h = n / 3600; m = n / 60 % 60; s = n % 60; cout << h << " " << m << " " << s; return 0; }
- 1
信息
- ID
- 138
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- 递交数
- 1905
- 已通过
- 1006
- 上传者