链接:https://ac.nowcoder.com/acm/contest/908/G
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld
题目描述
A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. For example, ”a”、”aba”、“abba” are palindrome and “abc”、”aabb” are not.
Let’s define a new function f(s).
For some string s, f(s) is the length of the longest palindrome substring.
Now you should decide for the given string s, whether f(s) is great than 1.
The string s only contains lowercase letters.
输入描述:
The first line of the input contains one integer n ------ the length of the string (1<=n<=10^5) The second line of the input is the string.
输出描述:
If f(s) great than 1, print “YES” without quote Else print “NO” without quote
示例1
输入
4 abcd
输出
NO
示例2
输入
4 abcb
输出
YES
题意:判断给出串中是否存在长度大于1的回文子串。
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int n;
char str[100050];
cin>>n>>str;
int fg = 0;
for(int i = 1; i < n; i++)
{
if(str[i]==str[i-1])
{
fg = 1;
break;
}
}
if(fg==1)
{
cout<<"YES"<<endl;
return 0;
}
for(int i = 1; i < n-1; i++)
{
if(str[i-1] == str[i+1])
{
fg = 1;
break;
}
}
if(fg == 1)
{
cout<<"YES"<<endl;
return 0;
}
cout<<"NO"<<endl;
return 0;
}