You are not logged in. Please login at www.codechef.com to post your questions!

×

SPOJ problem NHAY TLE

Hi,

I tried to solve SPOJ problem NHAY (https://www.spoj.pl/problems/NHAY/) using KMP algorithm. The judge gives TLE though my code is in C++.

Please help me. Any small hint is appreciated.

Here is my code. https://ideone.com/Xd8vmU

asked 02 Feb '15, 17:39

vicky2135's gravatar image

4★vicky2135
112
accept rate: 0%


You should try simple string find function available in string container. Here is my implementation

include<bits stdc++.h="">

using namespace std; int main() { int x; while(scanf("%d",&x)!=EOF) { string pat,txt; cin>>pat; cin>>txt; int l=pat.size(); int m=txt.size(); if(l>m) { printf("\n"); } else { for(int i=0;i<m;i++) {="" int="" k="txt.find(pat,i);" if(k="">=0 && k<m) printf("%d\n",k); else break; i=k; } } printf("\n"); } return 0; }

if u have any query fill free to ask.

link

answered 03 Feb '15, 00:16

asvikr's gravatar image

5★asvikr
213
accept rate: 0%

link

answered 31 Mar '15, 22:28

pallesai's gravatar image

4★pallesai
176830
accept rate: 17%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,136
×720
×643
×70

question asked: 02 Feb '15, 17:39

question was seen: 5,343 times

last updated: 31 Mar '15, 22:28