您的位置:首页 > 其它

UVALive 6342 The Mirror of Galadriel (回文串)

2014-07-06 19:56 597 查看
The Mirror of Galadriel
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld
& %llu
SubmitStatusPracticeUVALive
6342

Description




With water from the stream Galadriel filled the basin to the brim, and breathed on it, and when the water was still again she spoke. 'Here is the Mirror of Galadriel,' she said. 'I have brought you here so that you may look in it, if you will.
For this is what your folk would call magic, I believe; though I do not understand clearly what they mean; and they seem also to use the same word of the deceits of the Enemy. But this, if you will, is the magic of Galadriel. Did you not say that you wished
to see Elf-magic?'
[align=RIGHT]- Galadriel to Frodo and Sam, describing her Mirror.[/align]

We call a string S magical if every substring of S appears in Galadriel's Mirror (under lateral inversion). In other words, a magical string is a string where every substring has its reverse
in the string.

Given a string S, determine if it is magical or not.

Input

The first line contains T, the number of test cases. The next T lines contain a string each.

Output

For each test case, output `YES' if the string is magical, and `NO' otherwise.

Constraints:

1<=T<=100

1<=| S|<=10

S contains only lower-case characters.

Notes/Explanation of Sample Input:

For the first test case, the list of substrings are : a, b, ab, ba, aba. The reverse of each of these strings is present as a substring of S too.

For the second test case, the list of substring are : a, b, ab. The reverse of `ab', which is `ba' is not present as a substring of the string.

Sample Input

2
aba
ab


Sample Output

YES
NO


AC代码:
#include <stdio.h>
#include <string.h>

int main(){
int n,len,i,flag;
char a[1000];
scanf("%d",&n);
while(n--){
flag=1;
scanf("%s",a);
len=strlen(a);
for(i=0;i<len/2;i++){
if(a[i]!=a[len-1-i]){
flag=0;
break;
}
}
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: