码迷,mamicode.com
首页 > 其他好文 > 详细

[虚拟机OA]Break a Palindrome 破坏回文串

时间:2019-09-12 09:33:11      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:输出   inpu   exp   graphic   orm   wing   破坏   graph   let   

In this challenge, you will be given a palindrome which you must modify if possible. Change exactly one character of the string to another character in the range ascii[a-z] so that the string meets the following two conditions:

• The new string is not a palindrome

• The new string is lower lexicographically (alphabetically) than the initial string.

• The new string is the lowest value string lexicographically that can be created from the original palindrome after making only one change.


If it not possible to create a string meeting the criteria, return the string IMPOSSIBLE.

Function Description

Complete the function breakPalindrome in the editor below. The function must return the resulting string or IMPOSSIBLE if one cannot be formed.
breakPalindrome has the following parameter(s):

s: the original string


Sample Case  
Sample Input For Custom Testing

bab

Sample Output 

aab

Explanation The string aab is the smallest string which satisfies all the given conditions.

 

题意:

给定?一个palindrome。要改变?一个char,使得新的string不不是palindrome。?而且要是lexicocographically最?小的,不不然就返回"IMPOSSIBLE"。

把左半边不不是a的改成a就?行行了了。举例例:输?aba。算法算出aaa但仍是回?文字串串,所以输出IMPOSSIBLE。 输?入abba,输出aaba。

 

思路:

代码:

 

[虚拟机OA]Break a Palindrome 破坏回文串

标签:输出   inpu   exp   graphic   orm   wing   破坏   graph   let   

原文地址:https://www.cnblogs.com/liuliu5151/p/11509825.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!