@saurabh
ur all test cases have count for each character >9 thats why its overwriting
the second digit ....
modified code is:-
#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++; printf("count=%d\n",count); }
else
{ if(count==1) str[j++]=tmp; else{ str[j++]=tmp;
sprintf(&str[j++],"%d",count); if(count>9) j++; } count=1; tmp=str[i]; }
}
//str[j++]=tmp; sprintf(&str[j++],"%d",count);
str[j]='\0';
printf("%s\n",str);
}
Now it has no bug
On Tue, Aug 9, 2011 at 8:53 PM, Dipankar Patro <[email protected]> wrote:
> Here is my code:
> http://ideone.com/deosU
>
> Same as that of Sagar's :D
> time O(n) and space O(1)
>
>
>
> On 9 August 2011 20:25, siddharam suresh <[email protected]> wrote:
>
>> saurabh
>> test my program
>> please tell me if any bug is there
>> Thank you,
>> Siddharam
>>
>>
>>
>> On Tue, Aug 9, 2011 at 8:18 PM, saurabh singh <[email protected]>wrote:
>>
>>> The code failed for all test cases I tried.....
>>>
>>>
>>> On Tue, Aug 9, 2011 at 8:15 PM, ankit sambyal <[email protected]>wrote:
>>>
>>>> ya got it now. I misunderstood the question
>>>>
>>>> --
>>>> 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.
>>>>
>>>
>>>
>>>
>>> --
>>> Saurabh Singh
>>> B.Tech (Computer Science)
>>> MNNIT 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.
>>>
>>
>> --
>> 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.
>>
>
>
>
> --
>
> ___________________________________________________________________________________________________________
>
> Please do not print this e-mail until urgent requirement. Go Green!!
> Save Papers <=> Save Trees
>
> --
> 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.