cswork / OA打开练习工作台

NvidiaOA #5

Break a Palindrome

估计中等可在线判题

考点(AI 标注)字符串贪心调度

Given a lowercase palindrome, change exactly one character so that the result is not a palindrome, is strictly smaller than the original string, and is the lexicographically smallest among all valid results; if there is no solution, output IMPOSSIBLE.

This site uses a standard input/output protocol.

输入格式

One line containing a lowercase palindrome of length 1..1000.

输出格式

Output the valid string or the uppercase IMPOSSIBLE.

样例 1

输入:

aaabbaaa

输出:

aaaabaaa

样例 2

输入:

aba

输出:

IMPOSSIBLE

样例 3

输入:

bb

输出:

ab

样例说明

Example 1: change the b at index 3 to a, giving aaaabaaa. Example 2: changing the center still gives a palindrome, and the other a characters cannot be lowered, so IMPOSSIBLE. Example 3: changing the first character to a gives ab, which is better than ba.