#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char * squeez(char *str)
{
char temp1[100];
char * temp;
temp=(char *) malloc(strlen(str)+1);
int start=0,cursor=0;
char mychar;
while(str[start]!='\0')
{
mychar=str[start];
while(str[start]==str[start+cursor]) cursor ++;
if(cursor==1)
sprintf(temp1,"%c",mychar);
else
sprintf(temp1,"%c%d",mychar,cursor);
strcat(temp,temp1);
start+=cursor;
cursor=0;
}
printf("%s\n",temp);
return (temp);
}
int main()
{
char str[100];
printf("enter the string:");
scanf("%s",str);
printf("The squeezed string is: %s",squeez(str));
}
Thank you,
Siddharam
On Tue, Aug 9, 2011 at 6:54 PM, Rohit Srivastava <[email protected]>wrote:
> google on RLE (run length encoding) its almost similar!!
>
>
> On Tue, Aug 9, 2011 at 6:46 PM, ankit sambyal <[email protected]>wrote:
>
>> @raghavan: ur approach uses O(n) space
>>
>> --
>> 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.
>>
>
> --
> 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.
>
--
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.