#C1327. Custom String Operations
Custom String Operations
Custom String Operations
You are required to implement a class CustomString
that supports several string operations. This class should keep track of an internal string and implement the following methods:
- reverse: Returns a new
CustomString
whose string is the reversal of the original. - is_palindrome: Checks whether the string is a palindrome. In this check, all non-alphanumeric characters should be ignored and letters compared in a case-insensitive manner. That is, let \( s \) be the string, then after cleaning, verify if \( s = s^R \) (where \( s^R \) is the reverse of \( s \)).
- count_vowels: Counts the total number of vowels (a, e, i, o, u in both uppercase and lowercase) present in the string.
- to_upper: Converts the string to uppercase and returns a new
CustomString
object.
Your implementation must read input from standard input (stdin) and produce output on standard output (stdout) as described below.
inputFormat
The first line contains an integer T
denoting the number of test cases. Each test case consists of two lines:
- The first line contains one of the following operation names:
reverse
,is_palindrome
,count_vowels
,to_upper
. - The second line contains the string to be processed. The string may contain spaces and punctuation.
For each test case, perform the corresponding operation on the given string.
outputFormat
For each test case, output the result on a new line:
- If the operation is
reverse
orto_upper
, output the resulting string. - If the operation is
is_palindrome
, outputTrue
if the string is a palindrome andFalse
otherwise. - If the operation is
count_vowels
, output the count of vowels (an integer).
4
reverse
hello
is_palindrome
A man a plan a canal Panama
count_vowels
hello world
to_upper
Python3
olleh
True
3
PYTHON3
</p>