Skip to content →

Tag: Algorithms

C++ STL Notes: String Replacement

Macro

You are asked to do some replacements on a string. Can you work it out?

Input and Output

 

Each test case will begin with a string in a single line, and followed by an integer N which means the number of replacements. The next N lines will give you two strings s1, s2, you should replace all the s1 into s2. For more details, see the
sample below.

Sample Input

 

abc
3
a b
bb a
c d
aaabaaaa
1
aa a

Sample Output

 

ad
aabaa

Note:
For the first sample:
After the first replacement, the string will be bbc.
After the second replacement, the string will be ac.
At last, the string will be ad.

My Code:

Leave a Comment