Question link: 11038-How Many O's? Question: The number of occurrences of 0 between [a. B. Idea: I started thinking about the digital DP at the beginning and found that it was quite complicated .. First, convert the problem to the number of 0-num. If we use the number of B minus the number of a, we only need to use the multiplication and addition principle of count, divide each digit of a number into the left and right sides, calculate the total number based on the multiplication principle, and add all the total numbers to the total number based on the addition principle. Then we will discuss the situation on both sides. For example, if 23045 sets the intermediate bit as mid, if the mid is not 0, and if it is 4, then there are [1-230] cases on the left, on the right side, there are [0-9] cases. If we seek 3, there will be [1-2] types on the left and [0-999] types on the right, because no matter how you obtain the right side, it cannot exceed the number. If the value of mid is 0, [1-22] on the Left can be randomly set to [1-100] on the right. If the value of 23 on the Left can only be set to [0-45] on the right. In this way, the code can be calculated from the low position to the high position:
# Include
# Include
Long a, B; long solve (long left) {if (left <0) return 0; long ans = 1, mid, right = 0, j = 1; while (left> = 10) {mid = left % 10; left/= 10; if (mid) ans + = left * j; else ans + = (left-1) * j + right + 1; right = right + mid * j; j * = 10;} return ans;} int main () {while (~ Scanf ("% lld", & a, & B) &! =-1 | B! =-1) {printf ("% lld \ n", solve (B)-solve (a-1);} return 0 ;}