回文处理(字符串)

A. Antipalindrome
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.

A substring s[lr]s[l…r] (1lr|s|1 ≤ l ≤ r ≤ |s|) of a string s=s1s2s|s|s = s1s2…s|s| is the string slsl+1srslsl + 1…sr.

Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word ss is changed into its longest substring that is not a palindrome. If all the substrings of ss are palindromes, she skips the word at all.

Some time ago Ann read the word ss. What is the word she changed it into?

Input

The first line contains a non-empty string ss with length at most 5050 characters, containing lowercase English letters only.

Output

If there is such a substring in ss that is not a palindrome, print the maximum length of such a substring. Otherwise print 00.

Note that there can be multiple longest substrings that are not palindromes, but their length is unique.

Examples
input
Copy
mew
output
Copy
3
input
Copy
wuffuw
output
Copy
5
input
Copy
qqqqqqqq
output
Copy
0
Note

"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is 33.

The string "uffuw" is one of the longest non-palindrome substrings (of length 55) of the string "wuffuw", so the answer for the second example is 55.

All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is 00


题意:找非回文.最长子字符串

#include<iostream>
#include <cstdio>
using namespace std;
string s;
int main()
{
 cin>>s;
for(int k=s.size();k>=0;k--)
  for(int i=0;i<=k/2;i++)
      if(s[i]!=s[k-i-1])
      {
         printf("%d\n",k);//压缩
          return 0;
      }
   puts("0");
  return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值