#include<iostream>

using namespace std;
string rev(string s)
{
  for(int i=1,j=s.size()-1;i<j;i++,j--)
    swap(s[i],s[j]);
  return s.substr(1);
}
int main()
{
  string s="WWWWWWWBWWWWWWWWWWWWWW";
  int rep=1;
  string s1="";
  for(int i=0;i<rep;i++)
    s1+=s;
  int count=0;
  bool flag=1;
  while(s1!="")
  {
    if(flag)
    {
      if(s1[0]=='W')
        s1=rev(s1);
      if(s1[0]=='B')
      {
        count++;
        s1=s1.substr(1);
        flag=!flag;
      }
    }
    else
    {
      if(s1[0]=='B')
        s1=rev(s1);
      if(s1[0]=='W')
      {
        count++;
        s1=s1.substr(1);
        flag=!flag;
      }
    }
  }
  cout<<count;

  system("pause");
}

On Apr 27, 9:11 am, Rujin Cao <drizzle...@gmail.com> wrote:
> For more solutions, you can find 
> herehttp://www.topcoder.com/stat?c=round_overview&er=5&rd=14433
> <http://www.topcoder.com/stat?c=round_overview&er=5&rd=14433>
>
> 2011/4/27 abhishek jain <abhi.creat...@gmail.com>
>
>
>
>
>
>
>
> > Hi,
>
> > As TC is over, so now I can submit the code of above prob:
>
> > import java.util.*;
> > import java.util.regex.*;
> > import java.text.*;
> > import java.math.*;
>
> > public class MathContest
> > {
> > public int countBlack(String ballSequence, int repetitions)
> > {
> >  int sl = ballSequence.length();
> > int l = sl*repetitions;
> > int a[] = new int[l];
> >  for(int i=0;i<repetitions;i++)
> > {
> >  for(int j=0;j<sl;j++)
> > {
> >  if(ballSequence.charAt(j)=='W')
> >  a[j+i*sl]=0;
> > else
> >  a[j+i*sl]=1;
> > }
> > }
> >  int count=0;
> > int i=0;
> >  while(i<l-1)
> > {
> > if(a[i]==0)
> >  {
> > for(int j=0;j<=(l-i-1)/2;j++)
> > {
> >  int temp = a[j+i+1];
> > a[j+1+i]= a[l-1-j];
> > a[l-j-1] = temp;
> >  }
> > }
> > else
> >  {
> > for(int j=i+1;j<l;j++)
> > {
> >  if(a[j]==0) a[j]=1;
> > else
> > a[j]=0;
> >  }
> > count++;
> > }
> >  i++;
> > }
> > if(a[l-1]==1)
> >  count++;
> > return count;
> >  }
>
> > Thanks,
> > Abhishek
>
> > On Tue, Apr 26, 2011 at 11:03 PM, Arpit Sood <soodfi...@gmail.com> wrote:
>
> >> @vaibhav he will be banned for sometime in topcoder if someone reports
> >> about this, you can count on that.....
>
> >> On Tue, Apr 26, 2011 at 10:42 PM, saurabh singh <saurab...@gmail.com>wrote:
>
> >>> Asking solution for a question 4m a live coding match is......
> >>> I am out of this topic.Apologies to anyone insulted 4m my side but i am
> >>> firm on wat i said.Leave the decision on the conscience of other readers.
>
> >>> On Tue, Apr 26, 2011 at 10:08 PM, vaibhav shukla <
> >>> vaibhav200...@gmail.com> wrote:
>
> >>>> I dont know y u ppl are so much concerned.He has just asked the
> >>>> question.Did any one answered it ??No,then y r u taking pain.
> >>>> and I dont know  how is this a disgrace on spirit of  coding ??Is asking
> >>>> a question a disgrace ?rubbish.
>
> >>>> On Tue, Apr 26, 2011 at 10:04 PM, radha krishnan <
> >>>> radhakrishnance...@gmail.com> wrote:
>
> >>>>> May be he s innocent
>
> >>>>> On Tue, Apr 26, 2011 at 10:02 PM, saurabh singh 
> >>>>> <saurab...@gmail.com>wrote:
>
> >>>>>> And sincerely hope no one helps him in near future too..........
>
> >>>>>> Disgrace on the spirit of coding
> >>>>>> On Tue, Apr 26, 2011 at 9:38 PM, radha krishnan <
> >>>>>> radhakrishnance...@gmail.com> wrote:
>
> >>>>>>> Are u mad man ?
> >>>>>>> WTF ?
> >>>>>>> wats ur TC handle ?
>
> >>>>>>> On Tue, Apr 26, 2011 at 9:22 PM, Aakash Johari <
> >>>>>>> aakashj....@gmail.com> wrote:
>
> >>>>>>>> You can ask the solution after the contest. :)
>
> >>>>>>>> On Tue, Apr 26, 2011 at 8:50 AM, Gunjan Sharma <
> >>>>>>>> gunjan.khan...@gmail.com> wrote:
>
> >>>>>>>>> @Kamlesh: In this world this thing is termed as cheating..... I
> >>>>>>>>> wish nobody helps u on this....
>
> >>>>>>>>> On Tue, Apr 26, 2011 at 9:17 PM, Saravanan T <
> >>>>>>>>> mail2sarava...@gmail.com> wrote:
>
> >>>>>>>>>> Post the question!
>
> >>>>>>>>>> On Tue, Apr 26, 2011 at 7:38 PM, kamlesh yadav <
> >>>>>>>>>> kamleshlu2...@gmail.com> wrote:
>
> >>>>>>>>>>> plaese be online at 8.30 pm today  if possible and please help
> >>>>>>>>>>> me.
>
> >>>>>>>>>>> On Tue, Apr 26, 2011 at 7:19 PM, kamlesh yadav <
> >>>>>>>>>>> kamleshlu2...@gmail.com> wrote:
> >>>>>>>>>>> > hello friends
> >>>>>>>>>>> >                          i NEED UR HUMBLE SUPPORT
>
> >>>>>>>>>>> >                           I will post a question after an hour,
> >>>>>>>>>>> if
> >>>>>>>>>>> > anybody can solve it for me as early as possible (probably
> >>>>>>>>>>> within 45
> >>>>>>>>>>> > minutes), then please solve it and send it ti me. I urgently
> >>>>>>>>>>> need it
> >>>>>>>>>>> > my id                kamleshlu2...@gmail.com
>
> >>>>>>>>>>> > --
> >>>>>>>>>>> > 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.
>
> >>>>>>>>>>> --
> >>>>>>>>>>> Kamlesh Kumar Yadav
> >>>>>>>>>>> MCA  Department of Computer Science
> >>>>>>>>>>> Delhi University
>
> >>>>>>>>>>> --
> >>>>>>>>>>> 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.
>
> >>>>>>>>> --
> >>>>>>>>> Regards
> >>>>>>>>> Gunjan Sharma
> >>>>>>>>> Chairman IEEE Students Chapter IIT Roorkee
> >>>>>>>>> B.Tech IV year CSE
>
> >>>>>>>>> Contact No- +91 9997767077
>
> >>>>>>>>>  --
> >>>>>>>>> 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.
>
> >>>>>>>> --
> >>>>>>>> -Aakash Johari
> >>>>>>>> (IIIT 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.
>
> >>>>>>>  --
> >>>>>>> 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.
>
> >>>>>> --
> >>>>>> 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 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.
>
> >>>> --
> >>>>   best wishes!!
> >>>> Vaibhav Shukla
> >>>>     DU-MCA
>
> >>>>  --
> >>>> 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.
>
> >>> --
> >>> 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 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.
>
> >> --
> >> Regards,
> >> Arpit Sood
>
> >> --
> >> 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.

Reply via email to