すべてのチャレンジ
簡単 0件解決済み 正答率0%

Hours, Minutes, and Seconds

Convert a duration in seconds to a compact readable string.

Split a duration into hours, minutes, and seconds. Write units as h, m, and s, in that order, with one space between units. Omit any zero-valued unit, except that zero seconds is written as 0s.

Implement format_duration(seconds).

Input

seconds: The total duration in seconds.

Output

Return the formatted duration, for example 2h 2m 5s.

制約

0 ≤ seconds ≤ 1,000,000,000. Hours may exceed 23; this is a duration, not a time of day.

例

例 1
入力:
seconds = 7325

期待される出力:
expected = "2h 2m 5s"
入力:
long long seconds = 7325;

期待される出力:
std::string expected = "2h 2m 5s";
入力:
long seconds = 7325;

期待される出力:
string expected = "2h 2m 5s";

解説

7325 = 2 × 3600 + 2 × 60 + 5.

例 2
入力:
seconds = 120

期待される出力:
expected = "2m"
入力:
long long seconds = 120;

期待される出力:
std::string expected = "2m";
入力:
long seconds = 120;

期待される出力:
string expected = "2m";

解説

120 seconds is exactly 2 minutes. Omit the zero hours and seconds.

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。