概述
http://www.elijahqi.win/archives/3538
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[l…r]
s[l…r]
(1≤l≤r≤|s|
1 ≤ l ≤ r ≤ |s|
) of a string s=s1s2…s|s|
s = s1s2…s|s|
is the string slsl+1…sr
slsl + 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 s
s
is changed into its longest substring that is not a palindrome. If all the substrings of s
s
are palindromes, she skips the word at all.
Some time ago Ann read the word s
s
. What is the word she changed it into?
Input
The first line contains a non-empty string s
s
with length at most 50
50
characters, containing lowercase English letters only.
Output
If there is such a substring in s
s
that is not a palindrome, print the maximum length of such a substring. Otherwise print 0
0
.
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 3
3
.
The string “uffuw” is one of the longest non-palindrome substrings (of length 5
5
) of the string “wuffuw”, so the answer for the second example is 5
5
.
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 0
0
.
模拟题意 暴力匹配即可
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
char s[110];
inline bool check(int l,int r){
for (;l<r;++l,--r) if(s[l]!=s[r]) return 1;
return 0;
}
int main(){
//freopen("a.in","r",stdin);
scanf("%s",s+1);int n=strlen(s+1),len;
for (len=n;len;--len){bool flag=1;
for (int i=1;i+len-1<=n;++i){
if(check(i,i+len-1)) {flag=0;break;}
}if (!flag) break;
}printf("%dn",len);
return 0;
}
最后
以上就是贪玩水池为你收集整理的codeforces 981 A Antipalindrome的全部内容,希望文章能够帮你解决codeforces 981 A Antipalindrome所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复