#218. 递归计数数组元素11
递归计数数组元素11
Recursive Count 11
Background
Congcong is learning recursion. He encountered an interesting problem that requires him to write a recursive function to solve.
Problem Description
Given an array of integers, compute recursively the number of times that the value 11 appears in the array. We will use the convention of considering only the part of the array that begins at the given . In this way, a recursive call can pass to move down the array. The initial call will pass as 0.
Input Format
Input is given from standard input in the following format.
The first line contains a string representation of an integer array, e.g.,
[1 2 11]. The second line contains an integer , representing the starting index to traverse the array.
Output Format
Output is printed to standard output in the following format.
An integer, representing the total number of times the value 11 appears in the array.
Sample
[1 2 11] 0
1
[11 11] 0
2
[1 2 3 4] 0
0
Sample Explanation
For the first sample, the value 11 appears once in the array [1, 2, 11], starting at index 0.
For the second sample, the value 11 appears twice in the array [11, 11], starting at index 0.
For the third sample, the value 11 does not appear in the array [1, 2, 3, 4], starting at index 0.
Constraints
Time limit: 1s, Memory limit: 1024KiB.