Palindrome
Time Limit:3000MS |
|
Memory Limit:65536K |
Total Submissions:33120 |
|
Accepted:11122 |
Description
A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inserted into the string in order to obtain a palindrome.
As an example, by inserting 2 characters, the string "Ab3bd" can be transformed into a palindrome ("dAb3bAd" or "Adb3bdA"). However, inserting fewer than 2 characters does not produce a palindrome.
Input
Your program is to read from standard input. The first line contains one integer: the length of the input string N, 3 <= N <= 5000. The second line contains one string with length N. The string is formed from uppercase letters from 'A' to 'Z', lowercase letters from 'a' to 'z' and digits from '0' to '9'. Uppercase and lowercase letters are to be considered distinct.
Output
Your program is to write to standard output. The first line contains one integer, which is the desired minimal number.
Sample Input
5
Ab3bd
Sample Output
2
分享到:
相关推荐
本程序可以判断字符串是否回文,在程序运行时输入所要判断的字符串,按回车后将输出是或不是回文。
可实现三种功能: (1)判断一整个字符串是否为回文; (2)判断指定位置的子串是否为回文; (3)输出此字符串中最长的子字符串;
else Console.WriteLine("该数组显然不是回文数组"); /*//第三个循环,输入数字b for (i = 0; i ; i++) { b[i] = char.Parse(Console.ReadLine()); } //第四个循环,输出数组b for (i = 0; i ; i++) ...
回文串是从左到右读与从右到左读字符方式一样的一个字符串,如ABCBA、eluparcettecrapule是回文串,但123431不是回文串。 编一个程序判断一个串是否为回文串。 键盘输入一个以回车结尾的字符串STR,如果是回文串,...
C语言源代码 判断字符串是否是回文。。。
资源--回文字符串
C语言用指针方式实现任意给定字符串的回文判定。
这个代码主要是判断一个字符串是否为回文。回文就是正着读和反着读是同一字符串,比如abcdbca就是一回文。
c语言代码写的回文字符串判断, for(i=0;i;) { if(str[i++]!=str[j--]) return 0;
顺序读入一个字符串数据(不含空格),判断能否将串中字符重新组合可以构成一个回文串。如用lvele可以构成回文串level、elvle,而用label则无法构成回文串。
对于一个从键盘输入的字符串,判断其是否为回文。回文即正反序相同。如“abba”是回文,而“abab”不是回文要求:(1)数据从键盘读入; (2)输出要判断的字符串; (3)利用栈的基本操作对给定的字符串判断其是否...
代码实现输入任意字符串,并计算输入字符串最大回文长度,并返回回文字符串。
找到字符串中最长的回文子串,并返回其长度
程判断输入的一串字符是否为“回文”。所谓“回文”是指顺序读和逆序读都一样的字符串。如:“12321”和“abcdcba”都是回文。
判断字符串是否“回文”(即顺读和逆读是相同的)
Manacher算法:求解最长回文字符串,时间复杂度为O(N) 回文串定义:“回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。回文子串,顾名思义,即字符串中满足回文性质的子串。
此代码为实现寻找一个长字符串的最大回文序列,回文指两边对称的字符串,分为字符数为奇数和偶数两种情况。
编写程序,验证一个字符串是否为回文串:是否从前读它和从后读它都是一样的。例如,mom,dad是回文串。该程序接收用户输入的字符串,判断是否为回文串,然后将判断的结果输出。在验证回文串时,忽略大小写、空格和...
本文实例讲述了Python回文字符串及回文数字判定功能。分享给大家供大家参考,具体如下: 所谓回文字符串,就是一个字符串,从左到右读和从右到左读是完全一样的。回文数字也是如此。 python2代码如下: def huiwen...
Leetcode 1312. 让字符串成为回文串的最少插入次数问题描述1312. 让字符串成为回文串的最少插入次数 - 力扣(LeetCode)算法解法1: 递