Expand alphabets occurrence
Expand alphabets occurrence
Problem:
A string consisting of short hand form of occurrence of alphabets will be passed as input. The program must expand the code and print the alphabets. Input Format: The first line will contain the short hand form of the code of length L.
Boundary Conditions:
2 <= L <= 20
Output Format: The alphabets occurrence based on the short hand code.
Example Input/Output 1:
Input:
a3b5a2
Output:
aaabbbbbaa
Explanation:
a3 implies a has to occur 3 times and hence a is printed thrice. b5 implies b has to be occur five times and hence b is printed five times. a2 again implies a has to occur 2 times and hence a is printed thrice.
Example Input/Output 2:
Input:
z2m6c4
Output:
zzmmmmmmcccc
Example Input/Output 3:
Input:
abc5
Output:
aaaaabbbbbccccc
Explanation:
Here there is no number after a and b. This implies the next immediate number of occurrence is applicable to both a and b. Hence 5 which occurs after c is applicable to a and b too. So all the three alphabets a,b,c are printed five times.
Program:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i;
char c;
while(scanf("%c%d",&c,&i)==2)
{
for(int j=0;j<i;j++)
{
printf("%c",c);
}
}
}
Comments
Post a Comment