CF1553D.Backspace

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two strings ss and tt, both consisting of lowercase English letters. You are going to type the string ss character by character, from the first character to the last one.

When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the last character you have typed among those that aren't deleted yet (or does nothing if there are no characters in the current string). For example, if ss is "abcbd" and you press Backspace instead of typing the first and the fourth characters, you will get the string "bd" (the first press of Backspace deletes no character, and the second press deletes the character 'c'). Another example, if ss is "abcaa" and you press Backspace instead of the last two letters, then the resulting text is "a".

Your task is to determine whether you can obtain the string tt, if you type the string ss and press "Backspace" instead of typing several (maybe zero) characters of ss.

给你两个字符串 ss 和 tt,二者均由小写英文字母组成。你需要逐个字符地输入字符串 ss,即从第一个字符开始,依次输入到最后一个字符。

在输入某个字符时,你可以不按下对应字母的按键,而是按下“退格”(Backspace)键。该操作会删除你当前已输入、且尚未被删除的字符中最后一个字符(若当前字符串为空,则该操作无效)。例如,若 ss 为 "abcbd",而你在输入第一个和第四个字符时改按 Backspace 键,则最终得到的字符串为 "bd"(第一次按 Backspace 时无字符可删,第二次按 Backspace 则删去字符 'c')。再举一例:若 ss 为 "abcaa",而你在输入最后两个字母时改按 Backspace 键,则最终文本为 "a"。

你的任务是判断:在输入字符串 ss 的过程中,是否可以通过将 ss 中若干(可能为零)个字符替换为按 Backspace 键的方式,恰好得到字符串 tt。

输入格式

The first line contains a single integer qq (1≤q≤1051 \le q \le 10^5) — the number of test cases.

The first line of each test case contains the string ss (1≤∣s∣≤1051 \le |s| \le 10^5). Each character of ss is a lowercase English letter.

The second line of each test case contains the string tt (1≤∣t∣≤1051 \le |t| \le 10^5). Each character of tt is a lowercase English letter.

It is guaranteed that the total number of characters in the strings over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 qq(1≤q≤1051 \le q \le 10^5),表示测试用例的数量。

每个测试用例的第一行包含字符串 ss(1≤∣s∣≤1051 \le |s| \le 10^5),ss 的每个字符均为小写英文字母。

每个测试用例的第二行包含字符串 tt(1≤∣t∣≤1051 \le |t| \le 10^5),tt 的每个字符均为小写英文字母。

保证所有测试用例中字符串的字符总数不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print "YES" if you can obtain the string tt by typing the string ss and replacing some characters with presses of "Backspace" button, or "NO" if you cannot.

You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).

对于每个测试用例,如果可以通过输入字符串 ss 并将其中某些字符替换为按“退格键(Backspace)”来得到字符串 tt,则输出 "YES";否则输出 "NO"。

你可以以任意大小写形式输出每个字母(例如,"YES"、"yes"、"Yes" 均被视为肯定回答;"NO"、"no"、"nO" 均被视为否定回答)。

输入输出样例

  • 输入#1

    4
    ababa
    ba
    ababa
    bb
    aaa
    aaaa
    aababa
    ababa

    输出#1

    YES
    NO
    NO
    YES

说明/提示

Consider the example test from the statement.

In order to obtain "ba" from "ababa", you may press Backspace instead of typing the first and the fourth characters.

There's no way to obtain "bb" while typing "ababa".

There's no way to obtain "aaaa" while typing "aaa".

In order to obtain "ababa" while typing "aababa", you have to press Backspace instead of typing the first character, then type all the remaining characters.

考虑题目陈述中的示例测试。

为了从字符串 "ababa" 得到 "ba",你可以按下退格键(Backspace),而不是输入第一个和第四个字符。

在输入 "ababa" 的过程中,无法得到 "bb"。

在输入 "aaa" 的过程中,无法得到 "aaaa"。

为了在输入 "aababa" 的过程中得到 "ababa",你必须在输入第一个字符时按下退格键,然后输入其余所有字符。

输入解题思路,AI测评打分。不知道怎么写?

首页