#K2561. Counting Character Occurrence Ignoring Case
Counting Character Occurrence Ignoring Case
Counting Character Occurrence Ignoring Case
Problem Description
Given a string s and a character c, count the number of times the character appears in the string, ignoring case differences. In other words, uppercase and lowercase versions of a letter are treated as the same.
Formally, if the input string is s and the character is c, then the answer is given by: $$\text{count} = \sum_{i=1}^{|s|} \mathbf{1}\{\text{tolower}(s_i)=\text{tolower}(c)\},$$ where \(\mathbf{1}\{\cdot\}\) is the indicator function.
Your program should read the input from standard input (stdin) and output the result to standard output (stdout).
inputFormat
The input consists of two lines:
- The first line is a non-empty string
s
. - The second line is a single character
c
whose occurrences you need to count ins
, ignoring case.
outputFormat
Output a single integer representing the count of occurrences of c
in s
in a case-insensitive manner.
Hello World
l
3