आसान 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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।