String Operations
Practice
3.7 (25 votes)
Basic programming
Basics of implementation
Easy
Implementation
String manipulation
Problem
55% Success 7081 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a string S.

Q number of operations are performed on string S.
In each of these Q operations, you are given an index \(ind\) and a character \(ch\). For each operation, you have to update character at index \(ind\) in string S to \(ch\), that is, after this operation \(S[ind] = ch\).
It is guaranteed that any index is updated atmost once.
We call the final string after performing Q number of operations as \(str\).

After this, M number of operations are performed on string \(str\).
In each of these M operations, you are given two indices a and b. For each operation, you have to reverse the substring that lies between the indices a and b (inclusive).
We call the final string after performing M operations as \(fin\).

Example: If string is "xyz" and
one of the Q operations is \(1 \; a\), then string "xyz" now becomes "ayz" as \(S[1]=a\) after the operation.
one of the M operations is \(1 \;3\), then "ayz" now becomes "zya" as the substring lying between indices 1 and 3 is reversed.

You have to print string \(str\), string \(fin\) and the number of indices which have same characters at them in both strings \(str\) and \(fin\).

Input Format:
First line consists of string S.
Next line consists of an integer denoting Q.
Following Q lines contain two integers each: \(ind\) and \(ch\).
Next line consists of an integer denoting M.
Following M lines contain two integers each: a and b.

Output Format:
In first line, print string \(str\).
In second line, print string \(fin\).
In third line, print the number of indices which have same characters at them in both strings \(str\) and \(fin\).

Input Constraints:
\(1 \le |S| \le 10^2\); S denotes length of string s.
\(1 \le Q \le |S|\)
\(1 \le M \le 10^3\)
\(1 \le ind \le |s|\), all \(ind\) values are unique.
\(1 \le a \le b \le |s|\)
\(ch\) will always be a lowercase English alphabet.
String S consists of lowercase English alphabets only.
All indices are 1 based.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
72 votes
Tags:
ApprovedBasic ProgrammingEasy
Points:20
34 votes
Tags:
ImplementationBasic ProgrammingBasics of Greedy Algorithms
Points:20
11 votes
Tags:
Easy