#K77772. Taco: Subsequence Checker
Taco: Subsequence Checker
Taco: Subsequence Checker
Given two strings s and p, determine whether p is a subsequence of s. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. Formally, you are to check if all characters of p appear in s in the same order (not necessarily contiguously).
For example, given s = "abcde"
and p = "ace"
, the function should output Yes
since "ace" is a subsequence of "abcde". Conversely, if s = "abcde"
and p = "aec"
, the solution should output No
.
The formal condition can be expressed using LaTeX. Let \( s = s_1 s_2 \ldots s_n \) and \( p = p_1 p_2 \ldots p_m \). Then, p is a subsequence of s if there exists indices \(1 \leq i_1 < i_2 < \dots < i_m \leq n\) such that:
[ s_{i_1} = p_1,\quad s_{i_2} = p_2,\quad \dots, \quad s_{i_m} = p_m ]
Your task is to implement this check and output the result accordingly.
inputFormat
The input is read from the standard input (stdin) and consists of two lines:
- The first line contains the string s (the main string).
- The second line contains the string p (the pattern string which might be a subsequence of s).
outputFormat
The output should be written to the standard output (stdout). Output a single line containing Yes
if p is a subsequence of s, or No
otherwise.
abcde
ace
Yes