#C10419. Count Digit Occurrences
Count Digit Occurrences
Count Digit Occurrences
You are given two inputs: a non-negative integer n and a single digit d (0-9). Your task is to count the number of times the digit d occurs in the decimal representation of n. For example, if n = 12034 and d = 2, the output should be 1 because the digit 2 appears only once in "12034". Use stdin to read the inputs and stdout to print the result.
The mathematical formulation of the problem can be stated as follows:
Given an integer \(n\) and a digit \(d\), compute:
[ \text{count}(n, d) = \text{the number of occurrences of } d \text{ in the string representation of } n. ]
Make sure to handle the case where n is 0 appropriately.
inputFormat
The input consists of a single line containing two values separated by spaces. The first value is the non-negative integer n and the second is the digit d (an integer from 0 to 9).
Example:
12345 3
outputFormat
Output a single integer representing the number of times the digit d appears in the decimal representation of n.
Example:
1## sample
12345 3
1