#C7267. String Character Replacement
String Character Replacement
String Character Replacement
Given an initial string s
and a series of queries, each consisting of a pair of characters (c1, c2)
, perform a replacement operation sequentially. For each query, replace every occurrence of c1
in the current string with c2
. After processing all queries in order, output the final string.
Note: The queries must be processed in the given order and the modifications made by previous queries will affect the subsequent ones.
For example, if s = "abcd"
and the queries are (a, x)
and (b, y)
, then the final output is "xycd"
.
inputFormat
The input is given via standard input and consists of multiple lines:
- The first line contains the initial string
s
. - The second line contains an integer
q
, which is the number of queries. - Each of the next
q
lines contains two space-separated characters,c1
andc2
, representing a query.
outputFormat
Output a single line containing the final string after applying all the queries.
## sampleabcd
2
a x
b y
xycd
</p>