I tried solving that prob..here's my code

#include<iostream>
#include<string>
using namespace std;
main()
{
 string s;
 cin>>s;
 while(1)
 {
     if(s.size()==1 && s[0]=='*')
       break;
     int length=1,curr=0,start=0,count=1;
     for(int i=1;i<s.size();i++)
     {
        if(s[i]!=s[curr] && s[i]!=s[start])
        {
              curr=0;
              count=1;
              length=i+1;
        }
        else if(s[i]!=s[start] && s[i]==s[curr])
        {
              curr++;
        }
        else if(s[i]==s[start] && s[i]!=s[curr])
        {
              length=i;
              curr=0;
              count=1;
              i=i-1;
        }
        else if(s[i]==s[start] && s[i]==s[curr])
        {
               if(i%length==0)
               {
                    count++;
                    curr++;
               }
               else
                    curr++;
        }
 }
 if(s[s.size()-1]==s[length-1])
 cout<<count<<"\n";
 else
 cout<<"1\n";
 cin>>s;
}
}

I am getting WA..anyone pls tel a testcase where the above code fails..pls..

Thanks in advance..

On Mon, Dec 6, 2010 at 5:44 PM, alexsolo <asp...@gmail.com> wrote:

> http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@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 algoge...@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