|
Problem # 6 : Shred-Merge
Two strings can be "shred-merged" to give a third string. Shred merging
involves splitting two input strings into many sub-strings and merging
them alternately as shown below :-
Shred = Shr + e + d
Merge = M + er + ge
And Shred + Merge can give Shr+M+e+er+d+ge = ShrMeerdge
(This is only one of many possible shred-merged forms of "Shred" and
Merge
. You can obtain different forms by splitting "shred" and "merge"
in different ways.)
Similarly
Complex = Co + m + p + lex
Simple = S + im + ple
Complex + Simple = CoSminpplelex
Write a function SHRED(A$
B$
C$) to find out whether the given string
C$ can be obtained by shred-merging A$ and B$.
It should return -1 if C$ is a shred-merged form of A$ and B$ and 0
if it is not.
Sample Output
| SHRED("correct"
wrong
cowrorngrect
) |
returns -1 |
| SHRED("jigsaw"
puzzle
jigsawpuzzle
) |
returns -1 |
| SHRED("inter"
intra
iintrntear
) |
returns -1 |
| SHRED("mixed"
well
mixweldle
) |
returns 0 |
| SHRED("too"
small
ts
) |
returns 0 |
NOTE: In the data above the characters the highlighted characters correspond to the characters belonging to the first string (only when the return value is -1).
|