#87Medium
Replace a substring
Time: 1 s · Memory: 256 MB
- Strings
Statement
You are given three strings , and . Replace every occurrence of in with . The search goes left to right: a found is replaced and the search continues after the replaced piece — so replacing aa with b in aaaa gives bb.
Input format
The first line contains ( to characters, words separated by single spaces), the second line and the third line ( to characters, no spaces).
Output format
The changed string.
Examples
Input
men maktabga boraman ma MA
Output
men MAktabga boraMAn
Input
aaaa aa b
Output
bb
Note
This is exactly what Python's s.replace(a, b) does. By hand: walk along ; if starts at the current position, append to the result and jump characters ahead, otherwise append the current character and move one step. ababab with ab → ba gives bababa.
