#C3597. Possible Barcode Restoration
Possible Barcode Restoration
Possible Barcode Restoration
Given a damaged 5-digit barcode where some digits are unreadable and represented by a '?' character, your task is to generate all possible valid barcodes by replacing each '?' with any digit (0–9). The resulting barcodes should be printed in ascending lexicographical order.
Note: The input barcode is always 5 characters long. For example, if the input is 12?45
, then the program should output:
12045 12145 12245 12345 12445 12545 12665 12745 12845 12945
However, when there are multiple '?' characters, all combinations (i.e. 10^k
possibilities if there are k
unknown digits) should be considered. All output barcodes must be printed in ascending order. If the input barcode has no '?' characters, simply output the barcode itself.
The underlying idea can be represented by the formula below where k is the number of '?':
[ \text{Total Possibilities} = 10^k ]
inputFormat
The input consists of a single line from stdin
containing a 5-character string representing the damaged barcode. Each character is either a digit ('0'-'9') or a '?' representing an unreadable digit.
outputFormat
Output all possible 5-digit barcodes by replacing '?' with digits from '0' to '9'. Each barcode should be printed on a separate line to stdout
in ascending lexicographical order.
12?45
12045
12145
12245
12345
12445
12545
12645
12745
12845
12945
</p>