#C13792. Anagram Checker
Anagram Checker
Anagram Checker
You are given two strings. Your task is to determine whether they are anagrams of each other. Two strings are anagrams if they consist of the same alphanumeric characters with the same frequencies, regardless of case, spaces, or punctuation.
Note: Only consider letters and digits. All other characters should be ignored. The order of the characters does not matter.
Example:
Listen
andSilent
are anagrams.A gentleman
andElegant man
are anagrams.Hello
andworld
are not anagrams.
The mathematical formulation of the problem can be expressed in LaTeX as:
\( S_1 \text{ is an anagram of } S_2 \iff \text{sort}(\{ c \in S_1 : c \in \text{Alnum}\}) = \text{sort}(\{ c \in S_2 : c \in \text{Alnum} \}) \)
inputFormat
The input consists of two lines. Each line contains a string. The first line is the first string and the second line is the second string.
For example:
A gentleman Elegant man
outputFormat
Output a single line with either True
or False
. Print True
if the two strings are anagrams of each other; otherwise, print False
.
For the above example, the output would be:
True## sample
Listen
Silent
True