4266: 回文
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1788 Solved: 544
Description
小王想知道一个字符串是否为
ABA’
型字符串。
ABA’
型字符串的定义:
S=ABA’
,
A
,
B
,
A’
都是原字符串的子串
(
不能是空串),
A’
的意思是
A
的反转串,
B
不一定要和
A
或
A’
不同。符合
ABA’
型的例如:
"aba”
,
"acbbca”
,
"abcefgcba”
等。
"Abcefgcba”
是
ABA’
型,因为它能找到一组对应的
A
(
"abc”)
,
B(”efg”)
和
A’("cba")
满足定义。
Input
第一行给测试总数
T(T <= 1000)
,接下来有
T
组测试数据。
每组测试数据有一行字符串
S(1 <= |S| <= 50000)
,字符串保证只有小写或大写英文字母。
Output
每组测试数据输出一行,如果
S
是
ABA’
型字符串,输出
"YES”
,否则输出
"NO"
。
Sample Input
5 abA gg Codeforces acmermca myacm
Sample Output
NO NO NO YES YES
HINT
Source
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <bitset>
#include <stack>
#include <map>
#include <climits>
#include <functional>
using namespace std;
#define LL long long
const int INF=0x3f3f3f3f;
char ch[50009];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s",ch);
int len=strlen(ch);
if(len<=2) {printf("NO\n");continue;}
if(ch[0]!=ch[len-1]) printf("NO\n");
else printf("YES\n");
}
return 0;
}