#4. 字符串单词替换为加号
字符串单词替换为加号
String Replacement with Word Preservation
Background
Congcong is playing a string processing game. He has a long string and wants to perform some special operations on it.
Problem Description
Given a string and a non-empty word string, return a version of the original string where all characters have been replaced by pluses ("+"), except for appearances of the word string which are preserved unchanged.
Input Format
Input is given from standard input in the following format.
S" "W
Output Format
Output is printed to standard output in the following format.
result_string
Sample
12xy34" "xy
"++xy++"
12xy34" "1
"1+++++"
12xy34xyabcxy" "xy
"++xy++xy+++xy"
Sample Explanation
- Sample 1: For string
S = "12xy34"and wordW = "xy",xyis preserved, and12and34are replaced by++. The result is"++xy++". - Sample 2: For string
S = "12xy34"and wordW = "1",1is preserved, and2xy34is replaced by+++++. The result is"1+++++". - Sample 3: For string
S = "12xy34xyabcxy"and wordW = "xy", all occurrences ofxyare preserved, and other characters are replaced by+. The result is"++xy++xy+++xy".
Constraints
Time limit: 1 second, Memory limit: 1024 KiB for each test case.