Re: [algogeeks] Re: string compress/expand

2011-10-03 Thread rahul sharma
plz run my code for test i/p:-

#include
#include
int main()
{
cout<<"\nenter the string";
char str[30];
cin>>str;
int c=1;

int index=0;
int i;
for(i=0;str[i];i++)
{

   //cout<<" check string "<1)
 {
//cout<<" count is "< wrote:

> Code for Compression
>
> I am doing it inplace
>
> void convert(char* s,int len){
> int i=0;
> int count=1;
> int index=1; //*maintain the index where number is to be added*
> for(i=1;i<=len;i++){
>if(s[i]==s[i-1])
>count++;
>else{
>s[index-1]=s[i-1];*//put the char first like a3abbb . then this
> step converts it into a3*
>s[index]= (count+'0');/*/convert the count integer into char
> so it becomes a3b4bb*
>count=1;
>index = index+2;
>}
> }
> s[index-1]='\0'*;//terminate the string* *(a3b4bb will become a3b4)*
>
> }
>
> On Mon, Oct 3, 2011 at 12:12 PM, rahul sharma wrote:
>
>> check my code for compression..
>>
>> check if it is ok
>> abc i/p
>> o/p abc
>>
>> means if character has no count.but still present in string it is its only
>> occurance.plz check that code...
>>
>> #include
>> #include
>> int main()
>> {
>> cout<<"\nenter the string";
>> char str[30];
>> cin>>str;
>> int c=1;
>> for(int i=0;str[i];i++)
>> {
>> if(str[i+1]>='0' && str[i+1]<='9')
>> {
>> c=c+(str[i+1]-'0');
>> for(int j=1;j> cout<>   i++;
>>
>> }
>>
>>else
>>cout<>c=1;
>>
>>
>> }
>>
>> getch();
>>
>>}
>>
>>
>>
>> On Mon, Oct 3, 2011 at 12:08 PM, Rahul Verma wrote:
>>
>>> @rahul sharma
>>>
>>> for that you have to check that string is alphanumeric or not. if it is
>>> alphanumeric then you have to call the function exapansion else you have to
>>> call the compression function.
>>>
>>> and
>>>
>>> if the desired output for *abc *is *a1b1c1* then you have to call the 
>>> *exapnsion
>>> function* or if the desired output is *abc* then you have to add a
>>> feature in the *compression function* i.e. in output the string have to
>>> omit the 1's
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/algogeeks/-/8olzJ_YJVWMJ.
>>>
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> 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 algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> 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 algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: string compress/expand

2011-10-03 Thread Anil Arya
compression
#include
#include
#include
#define MAX_RLEN 50

/* Returns the Run Length Encoded string for the
   source string src */
char *encode(char *src)
{
  int rLen;
  char count[MAX_RLEN];
  int len = strlen(src);

  /* If all characters in the source string are different,
then size of destination string would be twice of input string.
For example if the src is "abcd", then dest would be "a1b1c1"
For other inputs, size would be less than twice.  */
  char *dest = (char *)malloc(sizeof(char)*(len*2 + 1));

  int i, j = 0, k;

  /* traverse the input string one by one */
  for(i = 0; i < len; i++)
  {

/* Copy the first occurrence of the new character */
dest[j++] = src[i];

/* Count the number of occurrences of the new character */
rLen = 1;
while(i + 1 < len && src[i] == src[i+1])
{
  rLen++;
  i++;
}

/* Store rLen in a character array count[] */
sprintf(count, "%d", rLen);

/* Copy the count[] to destination */
for(k = 0; *(count+k); k++, j++)
{
  dest[j] = count[k];
}
  }

  /*terminate the destination string */
  dest[j] = '\0';
  return dest;
}

/*driver program to test above function */
int main()
{
  char str[] = "geeksforgeeks";
  char *res = encode(str);
  printf("%s", res);
  getchar();
}

Time Complexity: O(n

On 10/4/11, Ankur Garg  wrote:
> Code for Compression
>
> I am doing it inplace
>
> void convert(char* s,int len){
> int i=0;
> int count=1;
> int index=1; //*maintain the index where number is to be added*
> for(i=1;i<=len;i++){
>if(s[i]==s[i-1])
>count++;
>else{
>s[index-1]=s[i-1];*//put the char first like a3abbb . then this
> step converts it into a3*
>s[index]= (count+'0');/*/convert the count integer into char  so
> it becomes a3b4bb*
>count=1;
>index = index+2;
>}
> }
> s[index-1]='\0'*;//terminate the string* *(a3b4bb will become a3b4)*
> }
>
> On Mon, Oct 3, 2011 at 12:12 PM, rahul sharma
> wrote:
>
>> check my code for compression..
>>
>> check if it is ok
>> abc i/p
>> o/p abc
>>
>> means if character has no count.but still present in string it is its only
>> occurance.plz check that code...
>>
>> #include
>> #include
>> int main()
>> {
>> cout<<"\nenter the string";
>> char str[30];
>> cin>>str;
>> int c=1;
>> for(int i=0;str[i];i++)
>> {
>> if(str[i+1]>='0' && str[i+1]<='9')
>> {
>> c=c+(str[i+1]-'0');
>> for(int j=1;j> cout<>   i++;
>>
>> }
>>
>>else
>>cout<>c=1;
>>
>>
>> }
>>
>> getch();
>>
>>}
>>
>>
>>
>> On Mon, Oct 3, 2011 at 12:08 PM, Rahul Verma
>> wrote:
>>
>>> @rahul sharma
>>>
>>> for that you have to check that string is alphanumeric or not. if it is
>>> alphanumeric then you have to call the function exapansion else you have
>>> to
>>> call the compression function.
>>>
>>> and
>>>
>>> if the desired output for *abc *is *a1b1c1* then you have to call the
>>> *exapnsion
>>> function* or if the desired output is *abc* then you have to add a
>>> feature in the *compression function* i.e. in output the string have to
>>> omit the 1's
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msg/algogeeks/-/8olzJ_YJVWMJ.
>>>
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> 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 algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> 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 algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>


-- 
*Anil  Arya,
Computer Science *
*Motilal Nehru National Institute of Technology,Allahabad .
*

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: string compress/expand

2011-10-03 Thread Ankur Garg
Code for Compression

I am doing it inplace

void convert(char* s,int len){
int i=0;
int count=1;
int index=1; //*maintain the index where number is to be added*
for(i=1;i<=len;i++){
   if(s[i]==s[i-1])
   count++;
   else{
   s[index-1]=s[i-1];*//put the char first like a3abbb . then this
step converts it into a3*
   s[index]= (count+'0');/*/convert the count integer into char  so
it becomes a3b4bb*
   count=1;
   index = index+2;
   }
}
s[index-1]='\0'*;//terminate the string* *(a3b4bb will become a3b4)*
}

On Mon, Oct 3, 2011 at 12:12 PM, rahul sharma wrote:

> check my code for compression..
>
> check if it is ok
> abc i/p
> o/p abc
>
> means if character has no count.but still present in string it is its only
> occurance.plz check that code...
>
> #include
> #include
> int main()
> {
> cout<<"\nenter the string";
> char str[30];
> cin>>str;
> int c=1;
> for(int i=0;str[i];i++)
> {
> if(str[i+1]>='0' && str[i+1]<='9')
> {
> c=c+(str[i+1]-'0');
> for(int j=1;j cout<   i++;
>
> }
>
>else
>cout
>
> }
>
> getch();
>
>}
>
>
>
> On Mon, Oct 3, 2011 at 12:08 PM, Rahul Verma wrote:
>
>> @rahul sharma
>>
>> for that you have to check that string is alphanumeric or not. if it is
>> alphanumeric then you have to call the function exapansion else you have to
>> call the compression function.
>>
>> and
>>
>> if the desired output for *abc *is *a1b1c1* then you have to call the 
>> *exapnsion
>> function* or if the desired output is *abc* then you have to add a
>> feature in the *compression function* i.e. in output the string have to
>> omit the 1's
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/algogeeks/-/8olzJ_YJVWMJ.
>>
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> 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 algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: string compress/expand

2011-10-02 Thread rahul sharma
check my code for compression..

check if it is ok
abc i/p
o/p abc

means if character has no count.but still present in string it is its only
occurance.plz check that code...

#include
#include
int main()
{
cout<<"\nenter the string";
char str[30];
cin>>str;
int c=1;
for(int i=0;str[i];i++)
{
if(str[i+1]>='0' && str[i+1]<='9')
{
c=c+(str[i+1]-'0');
for(int j=1;jwrote:

> @rahul sharma
>
> for that you have to check that string is alphanumeric or not. if it is
> alphanumeric then you have to call the function exapansion else you have to
> call the compression function.
>
> and
>
> if the desired output for *abc *is *a1b1c1* then you have to call the 
> *exapnsion
> function* or if the desired output is *abc* then you have to add a feature
> in the *compression function* i.e. in output the string have to omit the
> 1's
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/8olzJ_YJVWMJ.
>
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: string compress/expand

2011-10-02 Thread Rahul Verma
@rahul sharma
 
for that you have to check that string is alphanumeric or not. if it is 
alphanumeric then you have to call the function exapansion else you have to 
call the compression function.
 
and
 
if the desired output for *abc *is *a1b1c1* then you have to call the 
*exapnsion 
function* or if the desired output is *abc* then you have to add a feature 
in the *compression function* i.e. in output the string have to omit the 1's 

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/8olzJ_YJVWMJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: string compress/expand

2011-10-02 Thread rahul sharma
m talking for string expansion version ..that if i/p like aaabbbccc
then o/p   a3b3c3

n wat to do for abc i/p in that case???

On Mon, Oct 3, 2011 at 11:13 AM, rahul sharma wrote:

> @rahul verma
>
> yeah i know supposes i m doing for
>
> a3b3c3..
>
> o/p :- aaabbbccc
>
>
> if i give i/p: abc to same program
> then should it accept n display then errorrcoz abc not
> accepted...a1b1c1 is aceeptedor it will show abc as such..
> tell me wat to do for abc
>
>
> On Mon, Oct 3, 2011 at 11:04 AM, Rahul Verma wrote:
>
>> @Rahul
>>
>> Parse the string and check the next element of the array if it is exactly
>> the previous one then *increase the counter by 1* else no need to
>> increase the counter.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/algogeeks/-/M08JxV-GeAsJ.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: string compress/expand

2011-10-02 Thread rahul sharma
@rahul verma

yeah i know supposes i m doing for

a3b3c3..

o/p :- aaabbbccc


if i give i/p: abc to same program
then should it accept n display then errorrcoz abc not accepted...a1b1c1
is aceeptedor it will show abc as such..
tell me wat to do for abc

On Mon, Oct 3, 2011 at 11:04 AM, Rahul Verma wrote:

> @Rahul
>
> Parse the string and check the next element of the array if it is exactly
> the previous one then *increase the counter by 1* else no need to increase
> the counter.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/M08JxV-GeAsJ.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: string compress/expand

2011-10-02 Thread Rahul Verma
@Rahul 
 
Parse the string and check the next element of the array if it is exactly 
the previous one then *increase the counter by 1* else no need to increase 
the counter.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/M08JxV-GeAsJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.