#K45107. Count Character Occurrences
Count Character Occurrences
Count Character Occurrences
Given a string \( S \) and a character \( C \), your task is to count the number of times \( C \) occurs in \( S \). The comparison is case-sensitive, which means uppercase and lowercase letters are treated differently.
In mathematical terms, if \( S = s_1s_2\ldots s_n \), then you should compute the value:
\[ count = \sum_{i=1}^{n} \mathbf{1}_{\{s_i = C\}} \]
where \( \mathbf{1}_{\{s_i = C\}} \) is 1 if \( s_i = C \) and 0 otherwise.
Examples:
- Input: "ProgrammingIsFun" and "g" → Output: 2
- Input: "Count_ALL_the@Chars!" and "@" → Output: 1
- Input: "Hello_World!" and "o" → Output: 2
inputFormat
The input is given via standard input (stdin) and consists of two lines:
- The first line contains the string \( S \).
- The second line contains the character \( C \) to be counted in \( S \).
outputFormat
Output a single integer on standard output (stdout) which is the number of occurrences of \( C \) in \( S \).
## sampleProgrammingIsFun
g
2