this will work even if run length is 1.
#include<stdio.h>
#define MAX 1000
int copy(char *str,int len)
{
int max_len=MAX-1,i;
for(i=len-1;i>=0;i--)
{
str[max_len]=str[i];
max_len--;
}
return max_len+1;
}
void runLength(char *str)
{
unsigned int j,k=1,loop=0,res_len=0;
int i,n_start;
/*copying input to the end of the buffer*/
n_start=copy(str,strlen(str));
for(i=MAX-1;i>=n_start;i--)
{
if(str[i] >='0' && str[i]<='9')
{
/*converting to number*/
loop=(str[i]-'0')*k+loop;
k=k*10;
}
else
{
for(j=0;j<loop;j++)
{
str[res_len]=str[i];
res_len++;
}
loop=0;
k=1;
}
}
str[res_len]='\0';
printf("\nDecoded Msg = %s\n",str);
}
int main()
{
char str[MAX];
memset(&str,0,MAX);
printf("\nEnter String = ");
scanf("%s",str);
runLength(str);
return 1;
}
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.