@vaibhav :acc. to u Its giving 9 for "BGBBGGGBBBGBGB" bt it should be 8
....how?
my code:
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int i=0,s=0,count=0,c=0,flag=1;
char a[100005],ch;
scanf("%s",a);
while(a[i]!='\0')
{ if(flag) while(a[i]=='B') {i++; flag=0;} //except heading
'B'
while(a[i]=='G')
{count++; i++;}
s+=(count-1);
count=0;
while(a[i]=='B')
{c++; i++;}
s+=c;
c=0;
}
printf("%d\n",s);
}
return 0;
}
On Tue, Jun 28, 2011 at 12:50 AM, vaibhav agarwal <
[email protected]> wrote:
> @kartik also consider the case of GBGGGG the answer is 1 BGGGGG. ie
> trailing G's left.
> BBBBBGB leading B's left hence only one G followed by B therefore only one
> iteration.
>
> try out some cases u will find hw it wrks.
>
>
> On Tue, Jun 28, 2011 at 12:42 AM, vaibhav agarwal <
> [email protected]> wrote:
>
>> @kartik
>>
>> yup frgt to mention the last case 1 followed by zero's in that case number
>> of iterations is the no. of trailing zeroes.
>> GBGBBB
>> will have four iterations
>> 101000 = 1(one zero b/w two ones) + 3(last 1 followed by 3 zero's)
>>
>> BGBGBB,BBGBGB,BBBGBG,BBBBGG
>>
>> well logic is how hw mny jump of 1's u need to do to get it to the end of
>> the sequence.
>> GBG requires 1 iteration ie BGG
>>
>>
>> On Mon, Jun 27, 2011 at 11:27 PM, kartik sachan
>> <[email protected]>wrote:
>>
>>> HEY DUDE I AM NOT GETTING UR LOGIC AT ALL I THINK HOW U WILL SATISFY THIS
>>> CASE GBGBBB
>>>
>>> --
>>> 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.
>
--
Dileep Kumar
Computer Science & 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.