MUYPN - Editorial

Invert Case - EDITORIAL:

Practice

Contest

Author: karthikeya619

Editorialist: kishen1912000

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Implementation

PROBLEM:

Given a string, check if it has alphanumeric characters. If yes, invert the cases of the alphabets in it and print it, else print -1.

EXPLANATION:

The question is straight-forward. The main aim was to reduce the source code size. In python, there are in-built functions for strings like .isalnum() for checking if there are alphanumeric characters, and .swapcase() for inverting cases of the alphabets.

Check out the setter’s solution which uses 82 characters. This solution can be improved more. Feel free to share your approach, if it differs. Suggestions are always welcomed.

SOLUTIONS:

Setter's Solution
for i in range(int(input())):
    s=input()
    print(s.swapcase()if s.isalnum()else -1)