1650A. Deletions of Two Adjacent Letters

1650A. Deletions of Two Adjacent Letters

A. Deletions of Two Adjacent Letters

  • time limit per test2 seconds
  • memory limit per test256 megabytes
  • inputstandard input
  • outputstandard output

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

字符串s给定,字符串长度为奇数。字符串由拉丁字母表中的小写字母组成。

As long as the string length is greater than 1, the following operation can be performed on it: select any two adjacent letters in the string s 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 2.

只要字符串长度大于1,就可以对其执行以下操作:选择字符串中的任意两个相邻字母,并将其从字符串中删除。例如,从一个操作中的字符串“lemma”可以得到四个字符串中的任意一个:“mma”、“lma”、“lea”或“lem”。特别是,在一个操作中,字符串的长度减少了2。

Formally, let the string s have the form s=s1_1s2_2…sn_n (n>1). During one operation, you choose an arbitrary index i (1≤i<n) and replace s=s1_1s2_2…si+1_i+1si+2_i+2…sn_n.

形式上,让字符串s的形式为s=s1_1s2_2…sn_n(n>1)。在一次操作中,选择任意索引i(1≤i<n)并替换s=s1_1s2_2…si+1_i+1si+2_i+2…sn_n

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

对于给定的字符串s和字母c,确定是否有可能进行这样一系列操作,最终使等式s=c为真?换句话说,是否存在这样一个操作序列,该过程将以长度为1的字符串结束,该字符串由字母c组成?

Input

The first line of input data contains an integer t (1≤t≤103) — the number of input test cases.

输入数据的第一行包含一个整数t(1≤T≤103)-输入测试用例的数量。

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

下面是t用例的描述。每个测试用例由两行表示:

string s, which has an odd length from 1 to 49 inclusive and consists of lowercase letters of the Latin alphabet;is a string containing one letter c, where c is a lowercase letter of the Latin alphabet.

字符串s,奇数长度为1到49(含1到49),由拉丁字母表中的小写字母组成;是一个包含一个字母c的字符串,其中c是拉丁字母表中的小写字母。

Output

For each test case in a separate line output:

  • YES, if the string s can be converted so that s=c is true;
  • YES,如果字符串s可以转换为s=c为真;
  • NO otherwise.
  • NO,否则

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).

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

Example
input

5 abcde c abcde b x y aaaaaaaaaaaaaaa a contest t

output

YES NO NO YES YES

Note

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

在第一个测试用例中,s=“abcde”。你需要得到s=“c”。对于第一个操作,删除前两个字母,我们得到s=“cde”。在第二个操作中,我们删除了最后两个字母,因此我们得到了s=“c”的预期值。

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

在第三个测试用例s=“x”中,需要得到s=“y”。显然,这是不可能做到的。

Solution
Code
#include <iostream>
#include <string>
using namespace std;

//A. Deletions of Two Adjacent Letters
int main() {
    int t = 0;
    cin >> t;
    for (int i = 0;i < t;i++){
        string str;
        cin >> str;
        char c;
        cin >> c;
        int len = str.size();
        int cnt = 0;
        for(int j = 0;j < len;j++){
            if (str[j] == c && j % 2 == 0){
                cout << "YES" << endl;
                cnt = 1;
                break;
            }
        }
        if (cnt == 0){
            cout << "NO" << endl;
        }

    }
    return 0;
}
CodeForces 文章被收录于专栏

https://codeforces.ml/

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务