#C10035. String Compression

    ID: 39196 Type: Default 1000ms 256MiB

String Compression

String Compression

You are given an input that is supposed to represent a string. Your task is to compress the string by replacing each group of consecutive identical characters with the character followed by the number of times it appears consecutively.

The rules are as follows:

  • If the input is received as a valid string, it must be enclosed in double quotes " at the beginning and the end. For example: "aaabbc".
  • If the input is not provided as a string (i.e. it is not enclosed in double quotes), output Input is not a string.
  • If the content inside the quotes contains any non-alphabetic characters, output Only alphabetic characters allowed.
  • An empty input (with no characters) should produce an empty output.
  • If the conditions are met, compress the string by replacing each group of consecutive identical characters with that character and the count of its repetition. For example, "aaabbc" becomes a3b2c1.

Note: All formulas used are in \( \LaTeX \) format if needed.

inputFormat

The input is given from standard input (stdin) as a single line.

  • If the input line is non-empty and represents a string, it will be enclosed in double quotes " at the beginning and the end (e.g. "aaabbc").
  • If the input is not enclosed in double quotes, consider it as not a valid string and output Input is not a string.
  • An empty input should be treated as an empty string.

outputFormat

Output the compressed string to standard output (stdout). If the string contains any non-alphabetic characters, output Only alphabetic characters allowed instead. If the input is not a string, output Input is not a string.

## sample
"aaabbc"
a3b2c1