Problem Statement | |||||||||||||
S ::= T | bUa T ::= aTb | A | B U ::= aU | bU | a | b A ::= aA | a B ::= bB | bDisplayed above is a Context-Free Grammar (CFG). You begin with the string (quotes for clarity) "S", and apply replacement rules until your resulting string no longer contains any capital letters. The first line above says that S can be replaced with T or bUa. The other lines are similar. You will return a sequence of strings, beginning with "S" and ending with input, where each successive sequence element results from applying one of the replacement rules above. For example, if input is "aaabb" then you will return {"S","T","aTb","aaTbb","aaAbb","aaabb"} | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | input will contain between 1 and 50 characters inclusive. | ||||||||||||
- | Each character in input will be 'a' or 'b'. | ||||||||||||
- | There will be exactly one solution. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
| |||||||||||||
4) | |||||||||||||
| |||||||||||||
5) | |||||||||||||
|