方形字符串

A string is called square if it is some string written twice in a row. For example, the strings "aa", "abcabc", "abab" and "baabaa" are square. But the strings "aaa", "abaaab" and "abcdabc" are not square.

For a given string ss determine if it is square.

Input

The first line of input data contains an integer tt (1 \le t \le 1001≤t≤100) —the number of test cases.

This is followed by tt lines, each containing a description of one test case. The given strings consist only of lowercase Latin letters and have lengths between 11 and 100100 inclusive.

Output

For each test case, output on a separate line:

  • YES if the string in the corresponding test case is square,
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

Example

Input

10
a
aa
aaa
aaaa
abab
abcabc
abacaba
xxyy
xyyx
xyxy

Output

NO
YES
NO
YES
YES
YES
NO
NO
NO
YES

翻译:

如果一个字符串在一行中被写了两次,那么这个字符串就叫做square。 例如,字符串“aa”,“abcabc”,“abab”和“baabaa”是方形的。 但是字符串“aaa”,“abaaab”和“abcdabc”不是方形的。  

对于给定的字符串ss确定它是否是方形的。  

输入  

输入数据的第一行包含一个整数tt (1 * t * 1001≤t≤100)——测试用例的数量。  

接下来是tt行,每一行包含一个测试用例的描述。 给定的字符串仅由小写拉丁字母组成,长度在11到100100之间(含100100)。  

输出  

对于每个测试用例,输出在单独的行上:  

如果相应测试用例中的字符串是方形的,则为YES,  

没有否则。  

您可以在任何情况下输出YES和NO(例如字符串YES、YES、YES和YES将被识别为肯定的响应)。

思路:

  既然我们要比较前后两部分是否相同,那么我们可以用数组的形式表示,为了防止超时,我们首先可以通过对数组元素个数的判断来排除明显不是方形字符串的,如果是奇数,那么就可以直接输出NO,是偶数就进行之后的比较;我们可以挨个进行比较一旦出现不相同的情况即可跳出循环,输出NO。当所有的都比较完之后而且没有不相同的情况则输出YES。

代码:

#include<stdio.h>
#include<string.h>
int main()
{
	char a[105],b[105];
	int i,n,j,m,flag=0;;
	scanf("%d",&m);
	while(m--)
	{
		scanf("%s",a);
		getchar();
		n=strlen(a);
		flag=0;
		if(n%2==1)
		{
		//	flag=1;
			printf("NO\n");
		}	
		else
		{
			for(i=0;i<n/2;i++)
			{
				if(a[i]!=a[n/2+i])
				{
					flag=1;
					printf("NO\n");
					break;
				}
			}	
		if(flag==0)
		printf("YES\n");
		}			
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值