plz run my code for test i/p:-
#include<iostream.h>
#include<conio.h>
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 "<<str;
// getch();
if(str[i]!=str[i+1])
{
// cout<<"\n string at "<<index<<" vairbale "<<str[i];
str[index]=str[i];
if(c>1)
{
// cout<<" count is "<<c;
// cout<<"\n string at "<<index+1<<" vairbale "<<c;
// getch();
// cout<<" here m i "<<str;
str[index+1]=c+'0';
index++;
}
index++;
c=1;
}
else
c++;
}
//cout<<" index at end "<<index;
str[index]=str[i];
cout<<str;
getch();
}
dont look for prog...just give i/p n check that its doing inplaee
compression ....thnx in advance...reply asap
On Tue, Oct 4, 2011 at 4:39 AM, Ankur Garg <[email protected]> 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 a3bbbb*
> 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 <[email protected]>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<iostream.h>
>> #include<conio.h>
>> 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<c;j++)
>> cout<<str[i];
>> i++;
>>
>> }
>>
>> else
>> cout<<str[i];
>> c=1;
>>
>>
>> }
>>
>> getch();
>>
>> }
>>
>>
>>
>> On Mon, Oct 3, 2011 at 12:08 PM, Rahul Verma <[email protected]>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 [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.
>
--
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.