UVALive 6342 The Mirror of Galadriel (回文串)

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

Description

Download as PDF

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

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;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值