Simple ankit



#include<stdio.h>
#include<string.h>

main()
{
 int i,j=0,l,count;
 char str[100],tmp;

 printf("Please enter the string\n");
 fgets(str,100,stdin);

 l=strlen(str);
 tmp=str[0]; count=1;

 for(i=1;i<l;i++)
 {
   if(tmp==str[i])
   count++;
   else
   {  if(count==1) str[j++]=tmp; else{ str[j++]=tmp;
sprintf(&str[j++],"%d",count); } count=1; tmp=str[i]; }
 }
  //str[j++]=tmp; sprintf(&str[j++],"%d",count);
  str[j]='\0';

 printf("%s\n",str);
}


On Tue, Aug 9, 2011 at 7:05 PM, siddharam suresh <[email protected]>wrote:

> #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.
>



-- 
**Regards
SAGAR PAREEK
COMPUTER SCIENCE AND ENGINEERING
NIT ALLAHABAD

-- 
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.

Reply via email to