Submit | All submissions | Best solutions | Back to list |
UOFTAF - Foxic Expressions |
Let's talk about some definitions, shall we?
An uppercase letter is a character between "A'' and "Z'', inclusive. You knew that.
A string is a sequence of characters. You probably knew that.
A Foxic letter is a superior uppercase letter - namely, one of "F", "O", or "X". You probably didn't know that.
A Foxic string is a superior string, consisting only of Foxic letters. You didn't know that.
Finally, a Foxic expression is a special string, with each of its characters being either a Foxic letter, or an "n" immediately following a Foxic letter. A Foxic expression can be translated into a Foxic string by a three-step process. First, up to one character can be added, removed, or modified, provided that the resulting string is still a valid Foxic expression. Next, every Foxic letter immediately preceding an "n" is replaced by zero or more occurrences of that same letter. Finally, each "n" is removed. You most certainly did not know that.
There are $T$ ($1 \leq T \leq 100$) scenarios to consider, as described above. In each scenario, given a Foxic string $S$ of length $N$ ($1 \leq N \leq 100$) and a Foxic expression $E$ of length $M$ ($1 \leq M \leq 100$), you'd like to determine whether or not $E$ can be translated into $S$.
Input
Line 1: 1 integer, $T$
For each scenario:
Line 1: 1 integer, $N$
Line 2: 1 string, $S$
Line 3: 1 integer, $M$
Line 4: 1 string, $E$
Output
For each scenario:
The string "Yes" (without quotes) if $E$ can be translated into $S$, or "No" otherwise.
Example
Input: 2 5 OOOFO 7 OXnFOXn 3 FOX 7 OFnOXnO Output: Yes No
Explanation of Sample:
In the first scenario, one possible course of action is to erase the second character of $E$, leaving the Foxic expression "OnFOXn". Next, we may choose to replace the first "O" with three copies of "O", and the remaining "X" with zero occurrences of "X", since each of these precedes an "n" - this yields the string "OOOnFOn". Finally, after removing each "n", we are left with "OOOFO", which matches $S$. Replacing the second character with an "O" would have also been possible.
In the second scenario, it is impossible to translate $E$ into $S$ through any valid steps.
Added by: | SourSpinach |
Date: | 2013-05-17 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Own problem, used in the 2012 UofT ACM Tryouts |
hide comments
2014-04-16 18:54:49 Dejan Todorovic
@Petar Veličković zahvaljujem :) |
|
2014-04-14 17:28:12 PetarV
@Dejan: Yes, you may do that, as long as your string is still a valid Foxic expression. |
|
2014-04-05 16:54:35 Bharath Reddy
TLE in Python :( @author: Can you please increase time limit Last edit: 2014-04-05 17:20:37 |
|
2014-04-03 23:30:24 Bidzilya Vladislav
""First, up to one character can be added, removed, or modified, provided that the resulting string is still a valid Foxic expression." Is it means that in some string we can remove(for example)one character and add another character (but, of course, at most one operation of each type)? Excuse me for my bad English. |
|
2014-04-03 18:07:24 Dejan Todorovic
"First, up to one character can be added, removed, or modified, provided that the resulting string is still a valid Foxic expression." .Can we add,remove or change something to be 'n' or change 'n' to be 'F','O' or 'X'? |