#B3640. Word Reversal Transformation

    ID: 11299 Type: Default 1000ms 256MiB

Word Reversal Transformation

Word Reversal Transformation

Given a sentence consisting of words separated by single spaces, where each word is either a fully lowercase English word, a fully uppercase English word, or a natural number, your task is to perform the following operations:

  • Reverse the order of the words.
  • If a word is in lowercase, convert it to uppercase.
  • If a word is in uppercase, convert it to lowercase.
  • If a word is a natural number, reverse its digits.

For example, if the input is:

we choose TO go 2 the 123 moon

Then the output should be:

MOON 321 THE 2 GO to CHOOSE WE

Note: The transformation rules are applied individually to each word before reversing the order.

inputFormat

The input consists of a single line containing words separated by single spaces. Each word is either:

  • a fully lowercase English word,
  • a fully uppercase English word, or
  • a natural number (a non-negative integer with no leading signs).

outputFormat

Output the transformed sentence in a single line where the words appear in the reverse order after applying the respective transformations.

sample

we choose TO go 2 the 123 moon
MOON 321 THE 2 GO to CHOOSE WE