Problem
Übersetzung anzeigenSplit 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.
Einschränkungen
0 ≤ seconds ≤ 1,000,000,000. Hours may exceed 23; this is a duration, not a time of day.
Beispiele
Eingabe:
seconds = 7325
Erwartete Ausgabe:
expected = "2h 2m 5s"
Eingabe:
long long seconds = 7325;
Erwartete Ausgabe:
std::string expected = "2h 2m 5s";
Eingabe:
long seconds = 7325;
Erwartete Ausgabe:
string expected = "2h 2m 5s";
Erläuterung
7325 = 2 × 3600 + 2 × 60 + 5.
Eingabe:
seconds = 120
Erwartete Ausgabe:
expected = "2m"
Eingabe:
long long seconds = 120;
Erwartete Ausgabe:
std::string expected = "2m";
Eingabe:
long seconds = 120;
Erwartete Ausgabe:
string expected = "2m";
Erläuterung
120 seconds is exactly 2 minutes. Omit the zero hours and seconds.
Referenzen
Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.