Files
python/TangDou/JiShuanKe/2023-03-06/入门简单题.md
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

48 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 分秒必争
### 题目描述
蒜头君是一个勤奋的好孩子,每天都分秒必争的学习。
已知现在是 `h:m:s` 点,$h$ 表示小时,$m$ 表示分钟,$s$ 表示秒,那么也即现在是一天中的第 $h$ 小时,第 $m$ 分钟,第 $s$ 秒。其中 $0\leq h< 24,0\leq m< 60,0\leq s< 60$。
已知`0:0:0`是一天中的第 $0$ 秒,他想知道现在的时间是这一天中的第几秒。
蒜头君很快就想到了答案,因为 $1m=60s,1h=60m$,那么 $1h=60\times 60=3600s$,也即一分钟有 $60$ 秒,一小时有 $60$ 分钟,那么一小时有 $3600$ 秒,那么答案就是 $3600\times h+60\times m+s$。
现在蒜头君把这个问题抛给了你,你能回答这个问题吗?
### 输入格式
输入三个正整数 $h,m,s$,分别表示小时、分钟、秒。
### 输出格式
输出一个正整数,表示这是今天的第几秒。
### 数据范围
$0\leq h< 24,0\leq m< 60,0\leq s < 60$。
<div style="page-break-after: always"></div>
### 题解
因为 $1m=60s,1h=60m$,那么 $1h=60\times 60=3600s$,也即一分钟有 $60$ 秒,一小时有 $60$ 分钟,那么一小时有 $3600$ 秒,那么答案就是 $3600\times h+60\times m+s$。
#### 参考代码
```c++{.line-numbers}
#include <iostream>
using namespace std;
int main() {
int h, m, s;
cin >> h >> m >> s;
int ans = h * 3600 + m * 60 + s;
cout << ans << endl;
return 0;
}
```
<div style="page-break-after: always"></div>