ZGODAN
Time limit1sMemory limit32 MB
Given a non-handsome integer with up to 1000 digits, find the nearest integer whose consecutive digits alternate between even and odd, printing both on a tie.
- Level
Medium6 of 10
- Topics
- Greedy, String, Backtracking
- Solved
- No attempts yet
Problem
An integer is handsome if every pair of consecutive digits has different parity (one even, one odd). Single-digit numbers are handsome.
Given a positive integer that is not handsome, find the closest handsome integer(s). Distance is absolute difference. If two different handsome numbers tie for minimum distance, print the smaller, then the larger, separated by one space.
Input
One line with a positive integer of at most 1000 digits. is not handsome.
Output
Print the closest handsome number(s). If the tie is between two distinct numbers, print both in increasing order separated by a single space.