#K77437. Alternate Case and Reverse Words

    ID: 34864 Type: Default 1000ms 256MiB

Alternate Case and Reverse Words

Alternate Case and Reverse Words

You are given two strings. The first string requires you to toggle the case of every alphabetic character (i.e. uppercase letters become lowercase and vice versa), while non-alphabetic characters remain unchanged. The second string should have its words reversed.

For example, given the first string "Hello, World!", the output should be "hELLO, wORLD!" after toggling cases. Similarly, reversing the words of "Hello, World!" should result in "World! Hello,".

Note: In the second part, a "word" is defined as a sequence of characters separated by a single space. Use the split and join approach as in many high-level languages. In particular, if the input string contains consecutive spaces, they must be preserved as in the standard split by " " routine.

You need to implement both functionalities in a single program. The program reads from standard input and prints to standard output.

inputFormat

The input consists of exactly two lines:

  1. The first line is a non-empty string for which you need to toggle the case of each alphabetic character.
  2. The second line is a non-empty string whose words are to be reversed.

Leading, trailing, and multiple spaces in the second line should be handled according to the described behavior.

outputFormat

The output should contain exactly two lines:

  1. The first line is the result of applying the alternate-case function to the first input string.
  2. The second line is the result of reversing the order of words in the second input string.
## sample
Hello, World!
Hello, World!
hELLO, wORLD!

World! Hello,

</p>