Deletions of Two Adjacent Letters

The string sss is given, the string length is odd number. The string consists of lowercase letters of the Latin alphabet.

As long as the string length is greater than 111, the following operation can be performed on it: select any two adjacent letters in the string sss and delete them from the string. For example, from the string "lemma" in one operation, you can get any of the four strings: "mma", "lma", "lea" or "lem" In particular, in one operation, the length of the string reduces by 222.

Formally, let the string sss have the form s=s1s2…sns=s_1s_2 \dots s_ns=s1​s2​…sn​ (n>1n>1n>1). During one operation, you choose an arbitrary index iii (1≤i<n1 \le i < n1≤i<n) and replace s=s1s2…si−1si+2…sns=s_1s_2 \dots s_{i-1}s_{i+2} \dots s_ns=s1​s2​…si−1​si+2​…sn​.

For the given string sss and the letter ccc, determine whether it is possible to make such a sequence of operations that in the end the equality s=cs=cs=c will be true? In other words, is there such a sequence of operations that the process will end with a string of length 111, which consists of the letter ccc?

Input

The first line of input data contains an integer ttt (1≤t≤1031 \le t \le 10^31≤t≤103) — the number of input test cases.

The descriptions of the ttt cases follow. Each test case is represented by two lines:

  • string sss, which has an odd length from 111 to 494949 inclusive and consists of lowercase letters of the Latin alphabet;
  • is a string containing one letter ccc, where ccc is a lowercase letter of the Latin alphabet.

Output

For each test case in a separate line output:

  • YES, if the string sss can be converted so that s=cs=cs=c is true;
  • NO otherwise.

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

Sample 1

InputOutput
5
abcde
c
abcde
b
x
y
aaaaaaaaaaaaaaa
a
contest
t
YES
NO
NO
YES
YES

Note

In the first test case, sss="abcde". You need to get sss="c". For the first operation, delete the first two letters, we get sss="cde". In the second operation, we delete the last two letters, so we get the expected value of sss="c".

In the third test case, sss="x", it is required to get sss="y". Obviously, this cannot be done.

思路:

满足条件:找到的字符左右为偶数就很好。

细节:字符不止一个,满足一个就行。

#include<iostream>
#include<string.h>
using namespace std;
const int N=50;
char a[N];
char A;
int t,n[N];
int len;
int j,flag;
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		j=0,flag=0;
		for(int i=0;i<N;i++)
			n[i]=0;
		scanf("%s",a);
		cin>>A;
		len=strlen(a);	
		for(int i=0;i<len;i++)
		{
			if(a[i]==A)
			{
				n[j]=i+1;
				j++;
			}
		}
		for(int i=0;n[i];i++)//是否存在 
		{
			if(n[i]%2)//YES
				flag=1;
		}	
		if(flag==0)
			printf("NO\n");
		else
			printf("YES\n");
	}
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TherAndI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值