UVALive 6342 The Mirror of Galadriel (回文串)
发布日期:2021-11-06 16:56:35 浏览次数:3 分类:技术文章

本文共 1727 字,大约阅读时间需要 5 分钟。

The Mirror of Galadriel
Time Limit:3000MS    Memory Limit:0KB    64bit IO Format:%lld & %llu

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?'
- Galadriel to Frodo and Sam, describing her Mirror.

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 : ababbaaba. 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 : abab. The reverse of `ab', which is `ba' is not present as a substring of the string.

Sample Input

2abaab

Sample Output

YESNO
AC代码:
#include 
#include
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

转载地址:https://blog.csdn.net/YJX_xx/article/details/37363021 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:UVALive 6345 The Glittering Caves of Aglarond (找规律求最多)
下一篇:UVALive 6340 Gandalf vs the Balrog(超坑)

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2024年04月22日 14时24分49秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章