nptel question 2

You are the encoded form of a data string as follows: consecutive
occurrences of a letter (up to 9) are represented by the letter
followed by the number of occurrences.

For example, the string

a9a3b2c4de

stands for the string

aaaaaaaaaaaabbccccdc

  • that is, 12 consecutive occurrences of a, followed by 2 bs, and then
    4 cs, followed by a d and finally c

Given an encoded form, you have to output the data string.

Input

The encoded form of the string, made as per the following rules.

  1. If a character occurs only once, then in the encoded string, it
    appears as such (for example, ā€˜dā€™ in the above string.)
  2. If the number of consecutive occurrences of the character is
    between 2 and 9, then it is represented as the character followed
    by the number of occurrences (e.g. aaaab is represented as a4b).
  3. If the number of consecutive occurrences of a character is greater
    than 9, then group 9 occurrences as per rule 2. Iterate the set of
    rules on the remaining string.

Output

The original string, consisting only of characters whose
encoding was given as input.

#include <stdio.h>
#include <stdlib.h>

int main()
{
int c;
int temp,i;
c = getchar();

while ( c != EOF && c !='\n' )
{

    if(c>=97 && c<=122)
     {
          temp=c;
          printf("%c",temp);
     }
     else if(c>=50 && c<=57)
     {
         for(i=0;i<(c-49);i++)
            printf("%c",temp);
     }

    c = getchar();

}

return 0;

}

//