加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 07:47:31 所属栏目:Java 来源:网络整理
导读: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 st

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。

?

思路:

代码:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读