You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.4 KiB

分秒必争

题目描述

蒜头君是一个勤奋的好孩子,每天都分秒必争的学习。

已知现在是 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

题解

因为 1m=60s,1h=60m,那么 1h=60\times 60=3600s,也即一分钟有 60 秒,一小时有 60 分钟,那么一小时有 3600 秒,那么答案就是 3600\times h+60\times m+s

参考代码

#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;
}