An archivist restores ancient scrolls, each inscribed with a single unbroken line of lowercase glyphs. Every scroll also bears one designated seal glyph. To lift a scroll's binding curse, the archivist must reverse the run of glyphs starting at the very first character of the scroll and ending at the first occurrence of the seal glyph, inclusive; every glyph after that point must stay exactly where it is. If the seal glyph never appears anywhere on the scroll, the curse does not apply and the scroll must be left completely untouched. Given a scroll's text and its seal glyph, output the scroll's text after the curse has been lifted.
A single line containing the scroll's text s, followed by a space, followed by the seal glyph ch.
Print the resulting scroll text on one line.
Example 1
Input
hello z
Expected
hello
Explanation
The seal glyph z never appears in "hello", so the curse does not apply and the scroll is printed unchanged: hello.
Example 2
Input
abcabcabcabc c
Expected
cbaabcabcabc
Explanation
The first occurrence of the seal glyph c is the third character (index 2). Reversing the prefix "abc" gives "cba"; appending the untouched remainder "abcabcabc" produces cbaabcabcabc.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →