#C11329. Perform Operations on a String

    ID: 40633 Type: Default 1000ms 256MiB

Perform Operations on a String

Perform Operations on a String

You are given a string \(s\) and a sequence of \(n\) operations to perform on \(s\). The operations can be of three types:

  • reverse: Reverse the entire string \(s\).
  • remove c: Remove all occurrences of character \(c\) from the string \(s\).
  • count c: Count the number of occurrences of character \(c\) in the string \(s\) and output the count.

Operations are applied sequentially. Only the results from the count operations should be printed as output. If there is no count operation, nothing should be output. Note that once an operation is applied, the string \(s\) is modified accordingly for subsequent operations.

For example, given \(s = \texttt{abacaba}\) and operations: [count a, remove a, count a, reverse, count b], the output should be:

4
0
2

inputFormat

The input is given via standard input (stdin) and has the following format:

  1. A line containing the string \(s\) (non-empty).
  2. A line containing an integer \(n\), the number of operations.
  3. \(n\) lines, each representing an operation. Each operation is either "reverse", "remove c" or "count c", where c is a single character.

outputFormat

The output is printed to standard output (stdout). For each count operation, print the resulting count on a new line, in the order the operations appear. If there are no count operations, output nothing.

## sample
abacaba
5
count a
remove a
count a
reverse
count b
4

0 2

</p>