056. Stopwatch issues

Codeforces
IDCF10269056
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
You like to use your stopwatch all the time, but there is one major problem with it. The stopwatch only displays seconds, so when it says 472 seconds have passed you have no idea what that means. Given a time in seconds display the years, days, hours, minutes and seconds that have passed. The first line is number of seconds that have gone by. Print the time that has passed in the following format. "X years, X days, X hours, X minutes and X seconds". If the value for any time is 0, do not include it. Also be sure to watch out for plurals and using "and". If the time is 0, say "now" . ## Input The first line is number of seconds that have gone by. ## Output Print the time that has passed in the following format. "X years, X days, X hours, X minutes and X seconds". If the value for any time is 0, do not include it. Also be sure to watch out for plurals and using "and". If the time is 0, say "now" . [samples]
**Definitions** Let $ s \in \mathbb{Z}_{\geq 0} $ be the input time in seconds. **Constants** - $ 1 \text{ year} = 365 \times 24 \times 3600 = 31536000 $ seconds - $ 1 \text{ day} = 24 \times 3600 = 86400 $ seconds - $ 1 \text{ hour} = 3600 $ seconds - $ 1 \text{ minute} = 60 $ seconds **Compute** Let: - $ y = \left\lfloor \frac{s}{31536000} \right\rfloor $ - $ d = \left\lfloor \frac{s \bmod 31536000}{86400} \right\rfloor $ - $ h = \left\lfloor \frac{s \bmod 86400}{3600} \right\rfloor $ - $ m = \left\lfloor \frac{s \bmod 3600}{60} \right\rfloor $ - $ sec = s \bmod 60 $ **Objective** Output the string: - If $ s = 0 $: "now" - Else: Construct a list of non-zero components: $ \text{components} = \left\{ (y, \text{"year"}), (d, \text{"day"}), (h, \text{"hour"}), (m, \text{"minute"}), (sec, \text{"second"}) \right\} $ For each $ (v, unit) $, if $ v > 0 $, append: - $ v $ + " " + $ unit $ + ( "s" if $ v \neq 1 $ else "" ) Join all but the last component with ", ", and the last with " and " if more than one component exists.
API Response (JSON)
{
  "problem": {
    "name": "056. Stopwatch issues",
    "description": {
      "content": "You like to use your stopwatch all the time, but there is one major problem with it. The stopwatch only displays seconds, so when it says 472 seconds have passed you have no idea what that means. Give",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269056"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You like to use your stopwatch all the time, but there is one major problem with it. The stopwatch only displays seconds, so when it says 472 seconds have passed you have no idea what that means. Give...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ s \\in \\mathbb{Z}_{\\geq 0} $ be the input time in seconds.\n\n**Constants**  \n- $ 1 \\text{ year} = 365 \\times 24 \\times 3600 = 31536000 $ seconds  \n- $ 1 \\text{ day} = 24 \\times 3...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments