PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000006. Xóa dần chữ số (Removing Digits)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Xóa dần chữ số (Removing Digits)
Removing Digits
Source: CSES
Problem Statement
Given a positive integer , in one operation you may choose a nonzero digit appearing in the decimal representation of the current number and subtract that digit from the number.
Continue until the number becomes . Determine the minimum number of operations required.
Input
The input contains one positive integer .
Output
Print one integer: the minimum number of operations needed to reach .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
27
Output
5
Explanation
One valid sequence is , subtracting . It takes steps, and no shorter valid sequence exists.