#K616. Text Formatting Commands

    ID: 31345 Type: Default 1000ms 256MiB

Text Formatting Commands

Text Formatting Commands

This problem requires you to process a given text according to a series of formatting commands. The input consists of a sequence of commands followed by the text to be formatted. The commands are provided one per line, and the sequence is terminated by a line containing only END. After that, the remaining lines form the text.

The available commands are:

  • UPPER: Converts the entire text to uppercase.
  • LOWER: Converts the entire text to lowercase.
  • CAPITALIZE: Capitalizes the first letter of each word and converts the rest of the letters to lowercase.
  • LEFT N: Left-aligns the text in a field of width N (pads spaces on the right if necessary).
  • RIGHT N: Right-aligns the text in a field of width N (pads spaces on the left if necessary).
  • CENTER N: Centers the text in a field of width N (pads spaces equally on both sides; if an odd number of spaces is required, the extra space is added to the right).

The commands are applied in the order they are given. Your program should read the commands from standard input, then read the text, and finally output the formatted text to standard output. Note that the text is formed by joining all input text lines (after the END marker) with a single space.

For example, if the input is:

UPPER
END
hello world

the output will be:

HELLO WORLD

inputFormat

The input is given via standard input and consists of two parts:

  1. A series of lines containing formatting commands. The sequence of commands ends when a line with END is encountered. Do not process the END line as a command.
  2. One or more lines of text that need to be formatted. These lines should be joined with a single space between them before processing the commands.

outputFormat

Output the formatted text to standard output. The text should be transformed by applying the commands sequentially.

## sample
UPPER
END
hello world
HELLO WORLD