A string S is passed as input. S will contain multiple integer values with each integer value followed by an alphabet. The program must expand the alphabets based on the related integer value.
Input Format:
The first line contains S.
Output Format:
The first line contains the expanded string value.
Boundary Conditions:
Length of S is from 2 to 100.
Example Input/Output 1:
Input:
4a5h
Output:
aaaahhhhh
Explanation:
As it is 4a and 5h, four a's are printed followed by 5 h's
Example Input/Output 2:
Input:
1k2b4k
Output:
kbbkkkk
Program
#include<stdio.h>
#include <stdlib.h>
int main()
{
char S[100],num[100];
int i=0,j=0,cnt=0;
scanf("%s",S);
while(S[i]!='\0')
{
if (isdigit(S[i]))
{
j=0;
while(S[i]>='0' && S[i]<='9')
num[j++]=S[i++];
num[j]='\0';
cnt=atoi(num);
}
while (cnt>0)
{
printf("%c",S[i]);
cnt--;
}
++i;
}
}
OUTPUT
100q2w
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqww
Input Format:
The first line contains S.
Output Format:
The first line contains the expanded string value.
Boundary Conditions:
Length of S is from 2 to 100.
Example Input/Output 1:
Input:
4a5h
Output:
aaaahhhhh
Explanation:
As it is 4a and 5h, four a's are printed followed by 5 h's
Example Input/Output 2:
Input:
1k2b4k
Output:
kbbkkkk
Program
#include<stdio.h>
#include <stdlib.h>
int main()
{
char S[100],num[100];
int i=0,j=0,cnt=0;
scanf("%s",S);
while(S[i]!='\0')
{
if (isdigit(S[i]))
{
j=0;
while(S[i]>='0' && S[i]<='9')
num[j++]=S[i++];
num[j]='\0';
cnt=atoi(num);
}
while (cnt>0)
{
printf("%c",S[i]);
cnt--;
}
++i;
}
}
OUTPUT
100q2w
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqww