A14918 | Deletions of Two Adjacent Letters
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The string $s$ 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 $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$ .
Formally, let the string $s$ have the form $s=s_1s_2 \dots s_n$ ( $n>1$ ). During one operation, you choose an arbitrary index $i$ ( $1 \le i < n$ ) and replace $s=s_1s_2 \dots s_{i-1}s_{i+2} \dots s_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$ ?
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$ .
Formally, let the string $s$ have the form $s=s_1s_2 \dots s_n$ ( $n>1$ ). During one operation, you choose an arbitrary index $i$ ( $1 \le i < n$ ) and replace $s=s_1s_2 \dots s_{i-1}s_{i+2} \dots s_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$ ?
输入格式
The first line of input data contains an integer $t$ ( $1 \le t \le 10^3$ ) — the number of input test cases.
The descriptions of the $t$ cases follow. Each test case is represented by two lines:
- 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.
The descriptions of the $t$ cases follow. Each test case is represented by two lines:
- 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.
输出格式
For each test case in a separate line output:
- YES, if the string $s$ can be converted so that $s=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).
- YES, if the string $s$ can be converted so that $s=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).
输入输出样例
输入 #1
5 abcde c abcde b x y aaaaaaaaaaaaaaa a contest t
输出 #1
YES NO NO YES YES
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".
In the third test case, $s$ ="x", it is required to get $s$ ="y". Obviously, this cannot be done.
In the third test case, $s$ ="x", it is required to get $s$ ="y". Obviously, this cannot be done.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted