모든 챌린지
쉬움 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에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.

다른 사람의 풀이 보기

커뮤니티 솔루션

아직 공개된 풀이가 없습니다. 문제를 풀고 첫 풀이를 공유하세요.