The Joy of Computing using Python : Programming Exam 2 : Compress the String - Jun-Dec 2021

NPTEL PROGRAMMING ASSIGNMENTS


  The Joy of Computing using Python

Programming Exam 2 : Compress the String

Due on 2021-10-10, 21:00 IST

You are given a string S. Suppose a character 'c' occurs consecutively times in the string. Write a program to replace these consecutive occurrences of the character with '(X,c) ' in the string.

Input Format

A single line of input consisting of the string .

Output Format

A single line of output consisting of the modified string.

Sample Input 0:

1222311

Sample Output 0:

(1, 1) (3, 2) (1, 3) (2, 1)

Explanation:

First, the character 1 occurs only once and it is replaced by (1,1). Then the character 2 occurs 3 times and it is replaced by (3,2). The same procedure is followed for the rest of the characters in the string.

  


Post a Comment (0)
Previous Post Next Post