#209. 递归计数特殊8

    ID: 209 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatWarmup-2gesp5递归数学基础

递归计数特殊8

Count Eights Recursively

Background

Congcong is learning recursion, and Dawei has assigned him an interesting digit counting task.

Problem Description

Given a non-negative integer nn, compute recursively (no loops) the count of the occurrences of 88 as a digit. Except that an 88 with another 88 immediately to its left counts double, so 88188818 yields 44. Note that mod (n%10n \% 10) by 1010 yields the rightmost digit (126%10126 \% 10 is 66), while divide (n/10n / 10) by 1010 removes the rightmost digit (126/10126 / 10 is 1212).

Input Format

Input is given from Standard Input in the following format.

nn

Output Format

Output is printed to Standard Output in the following format.

The total count of occurrences of 88.

Sample

8
1
818
2
8818
4

Sample Explanation

For input 88188818:

  • The rightmost 88 (units digit) has no 88 to its left, counts as 11.
  • The digit 11 does not count.
  • The second 88 from the left (hundreds digit) has an 88 to its left (thousands digit), so it counts as 22.
  • The leftmost 88 (thousands digit) has no digit to its left, counts as 11. Total count is 1+0+2+1=41 + 0 + 2 + 1 = 4.

Constraints

Time limit: 1 second, Memory limit: 1024 KiB