Tag Archives: C String

Check whether string can be generated from given grammar ?

Write a code to check whether given string can be generated from given grammar ?

Grammar  :

S – > 122S
S – > 12S
S – > 1S
S – > “”

==================================================================================
Input :
12221
Output :
0

===================================================================================

Input :
121
Output:
1

====================================================================================

O = > False (Cannot be generated)

1 = > True (Can be generated)