#C3608. Ensure Section End

    ID: 47054 Type: Default 1000ms 256MiB

Ensure Section End

Ensure Section End

You are given a text string. Your task is to process the string so that it ends with the phrase [end of section]. If the string already ends with this phrase, return it unchanged; otherwise, first remove any trailing whitespace and then append a space followed by [end of section].

Note that if the phrase appears in the middle of the string or if the string ends with extra characters after the phrase, you should still append the phrase after the existing text.

For example:

  • This is a document section. [end of section] is unchanged.
  • This is a document section. becomes This is a document section. [end of section].
  • An input with trailing spaces will have those spaces removed before appending the phrase.
  • An empty string becomes [end of section].
  • If the string ends with [end of section] followed by extra text, the phrase must be appended again.

inputFormat

The input consists of a single string provided via standard input (stdin). The string may contain spaces, trailing whitespace, or even be empty.

outputFormat

Output the processed string via standard output (stdout) such that it ends with [end of section] following the rules described above.

## sample
This is a document section. [end of section]
This is a document section. [end of section]