输入包括一个整数n(1 ≤ n ≤ 1,000,000,000)
输出包括一行10个整数,即0~9这些数字在页码中出现的次数,以空格分隔。行末无空格。
999
189 300 300 300 300 300 300 300 300 300
def count_digit(n, x): high = n // 10 cur = n % 10 low = 0 digit = 1 res = 0 while high != 0 or cur != 0: if 0 <= cur < x: res += high * digit elif cur == x: if x == 0: res += (high - 1) * digit + low + 1 else: res += high * digit + low + 1 elif cur > x: if x == 0: res += high * digit else: res += (high + 1) * digit low += cur * digit cur = high % 10 high //= 10 digit *= 10 return res if __name__ == '__main__': n = int(input()) for i in range(9): print(count_digit(n, i), end=' ') print(count_digit(n, 9), end='')