Count occurrences of a digit MEDIUM Subprograme (BAC) 25 XP 0 solved
Mobile coding works. A laptop is faster for long sessions.

Problem

Write the definition of a subprogram `cif` that receives through parameter `a` a natural number with at most 9 digits and through parameter `b` a digit (`0 <= b <= 9`). The subprogram returns the number of occurrences of digit `b` in the base-10 representation of `a`. For `a = 0`, the number is considered to have a single digit, `0`. Then write a main program that reads from standard input a non-zero natural number `t`, then `t` pairs `(a, b)` separated by spaces or newlines, and prints on a separate line the value returned by the call `cif(a, b)` for each pair, in reading order.

Input format

Input input.txt

The first line contains the natural number `t`. The following lines contain `t` pairs of numbers `(a, b)`. - `1 <= t <= 100` - `0 <= a <= 999.999.999` - `0 <= b <= 9` - the subprogram `cif` must be defined explicitly and called from `main`

Output format

Output output.txt

The program prints `t` lines, each containing the number of occurrences of digit `b` in `a`.

Example

input
4
12321 1
12321 2
12321 5
0 0
output
2
2
0
1

Ready to solve this challenge?

Create a free account to write code, submit solutions, and track your progress.

⌨️ Keyboard Shortcuts

Code Editor
Run Code
Ctrl Enter
Submit Code
Ctrl Shift Enter
Format Code
Shift Alt F
Toggle Comment
Ctrl /
Undo
Ctrl Z
Redo
Ctrl Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc

🔍 Interactive Debugger

0 / 0

Analyzing your code...

📦 Variables

No variables yet

📚 Call Stack
main() line 1
📤 Output
We use cookies

Essential cookies are always active. You can choose to enable preference and analytics cookies. Learn more