#C13273. Case-Insensitive Character Occurrence Counter
Case-Insensitive Character Occurrence Counter
Case-Insensitive Character Occurrence Counter
Given a string s
and a character c
, count the number of times c
appears in s
, ignoring the case of both the string and the character. This problem is designed to test your ability to perform simple string manipulation and case normalization.
For example, if s = "Hello World"
and c = 'o'
, the correct count is 2 because both 'o' and 'O' are counted. In mathematical terms, if we define the function:
\( f(s, c) = \#\{ i \mid s_i = c \text{ or } s_i = \text{upper}(c) \} \)
then you are required to compute f(s, c)
for the provided input.
inputFormat
The input consists of two lines. The first line contains a non-empty string s
(which may include spaces). The second line contains a single character c
.
outputFormat
Output a single integer representing the number of occurrences of character c
in the string s
while ignoring the case of both.
Hello World
o
2