I tried the problem https://www.spoj.pl/problems/NHAY/

I didn't Understand the Input of the problem --
The length of the needle is only limited by the memory available to your
program, so do not make any assumptions - instead, read the length and
allocate memory as needed. The haystack is *not* limited in size, which
implies that your program should not read the whole haystack at once. The
KMP algorithm is stream-based, i.e. it processes the haystack character by
character, so this is not a problem.

my code works fine i the size of both the strings are limited

i created my own algo...didn't did it by KMP.....plz help me how to control
the large input !!


my code is--

#include<stdio.h>
#include<string.h>

int main()
{
    int t,i,j,n,l1,l2;
    char p[10000000],str[10000000];
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        i=0;
        scanf("%s",p);
        scanf("%s",str);
        l1=strlen(str);l2=strlen(p);
        for(j=0;j<l2;)
        {

                if(i<l1)
                {
                    if(str[i]==p[j])
                    {
                        if(j==l2-1)
                        {
                        printf("%d\n",i-l2+1);
                        j=0;
                        i=i-l2+2;
                        }
                        else
                        {
                        i++;
                        j++;
                        }
                    }
                    else
                    {
                        if(j==0)
                            i++;
                        else
                            j=0;
                    }
                }
                else
                    break;
        }
        printf("\n");
    }
return 0;
}

-- 
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.

Reply via email to