문제
번역본 보기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에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.