#C13360. Count Distinct Characters in a String
Count Distinct Characters in a String
Count Distinct Characters in a String
Given a string s consisting solely of lowercase letters, your task is to compute the number of distinct characters present in the string. You must solve the problem without using additional data structures such as sets, dictionaries, or arrays (other than the input string itself).
You can utilize bit manipulation as a clever alternative. By using a single integer as a bitmask, each bit can represent a character. For example, to mark that a character c is present, you can set the corresponding bit via the operation: \(\text{checker} |= (1 \ll (\text{ord}(c) - \text{ord}('a')))\). Finally, the number of set bits gives the count of distinct characters.
It is guaranteed that the input string will only contain lowercase alphabets from \(a\) to \(z\).
inputFormat
The input is read from standard input. A single line containing the string (s), where (s) is a sequence of lowercase letters.
outputFormat
Print to standard output a single integer representing the number of distinct characters present in (s).## sample
hello
4