#C1175. Minimum Number by Deleting One Digit
Minimum Number by Deleting One Digit
Minimum Number by Deleting One Digit
You are given a non-empty string S
consisting of digits (0-9). Your task is to remove exactly one digit from S
such that the resulting string represents the smallest possible number. Note that the resulting number should not have extra leading zeros (except when the number is zero itself).
Formally, if S
has length n, you are to choose an index i (1 ≤ i ≤ n) and remove the ith character from S
. This will yield a new string S'
. You must choose the removal that minimizes S'
(when compared as numbers, and with the convention that a string with leading zeros is interpreted in the usual way, except that the number 0 is represented as "0").
For instance, if S = "1432219"
, removing the first digit yields "432219", but removing the second digit results in "132219", which is smaller. Your solution should compute and output this minimum number.
The problem can be mathematically formulated as finding \[ \min_{1 \le i \le n} \; \text{val}(S_1 S_2 \dots S_{i-1} S_{i+1} \dots S_n), \] with the provision that if the result has leading zeros, they are removed (i.e., interpreted in standard decimal notation), and if the resulting string is empty or all zeros, output "0".
inputFormat
The input consists of a single line that contains the string S
made up of digits (0-9). This string represents a non-negative integer.
outputFormat
Output the smallest number (as a string) possible after deleting exactly one digit from S
. The output should not contain unnecessary leading zeros; if the result is empty or all zeros, output "0".
1432219
132219