#K4371. String Manipulation Operations

    ID: 27370 Type: Default 1000ms 256MiB

String Manipulation Operations

String Manipulation Operations

This problem requires you to perform various operations on a string according to given commands. You must implement three functions:

  • insert_character(s, pos, ch): Inserts the character ch into the string s at position pos. The position is 0-indexed.
  • delete_character(s, pos): Deletes the character in the string s located at position pos.
  • count_distinct_characters(s): Returns the number of distinct characters in the string s using \( \LaTeX \) notation for formulas when needed (e.g., \( |\{\text{characters in } s\}| \)).

You will be given an initial string and then a number of operations. The operations follow one of these formats:

  • I pos ch: Insert character ch at position pos.
  • D pos: Delete the character at position pos.
  • C: Count distinct characters in the current string and output the result.

Your program should process the commands in order and for each C command, output the number of distinct characters on a new line.

inputFormat

The input is read from stdin and has the following format:

  1. The first line contains the initial string s.
  2. The second line contains an integer Q, the number of operations.
  3. The following Q lines each contain one operation, which can be one of the following:
    • I pos ch — Insert character ch at index pos (0-indexed).
    • D pos — Delete the character at index pos.
    • C — Output the count of distinct characters in the string.

outputFormat

For each C command encountered in the input, output a single line containing the number of distinct characters in the string at that point. The output should be written to stdout.

## sample
abcde
5
I 3 z
C
D 0
C
I 0 x
6

5

</p>