提交时间:2025-01-04 12:04:20

运行 ID: 52172

n = int(input()) Queue = [i for i in range(1, 10)] # 从 1 到 9 初始化 count = 0 while Queue: num = Queue.pop(0) # 从队列取出第一个数 if num >= 10 and num <= n: count += 1 # 如果在范围内,计数 if num < n: last_digit = num % 10 for i in range(last_digit, 10): # 生成递增数 new_num = num * 10 + i if new_num <= n: Queue.append(new_num) print(count)