-4

I was able to test the below code for the sample input data given and was able to validate successfully.

http://rosalind.info/problems/1c/

But somehow for any dataset that I download, the answer is not being accepted by the website. I'm not sure If I am missing something.

I am using the naive indexOf function for this. Was not sure if KMP was really needed unless the input string was really big.

import java.util.*;
import java.lang.*;
import java.io.*;
class PatternMatch
{
    public static StringBuilder out = new StringBuilder();
    public static void main (String[] args) throws java.lang.Exception
    {
        try{
            System.out.println(match("GATATATGCATATACTT","ATAT",0));
        }catch(Throwable e){
            System.out.println("excepton "+e.getMessage());
        }
    }
    static String match(String text,String pat,int start){
        if(start+pat.length()-1<text.length()){
            int matchPos = text.indexOf(pat,start);
            if(matchPos>0){
                out.append(matchPos+" ");
                match(text,pat,matchPos+1);
            } else {
                return out.toString();  
            }
        } else {
            return out.toString();
        }
        return out.toString();
    }
}
crackerplace
  • 5,305
  • 8
  • 34
  • 42
  • I see negative votes,but no reason for that ? Is it not a right question ? – crackerplace Dec 22 '14 at 15:11
  • This question appears to be off-topic because it is about a private website and how it functions. – Erick Robertson Dec 22 '14 at 19:32
  • @ErickRobertson good that someone cared to explain.If that was done before I would have closed it straight away.I dont see any point in just voting down questions without a hint of whats wrong.My question still had a point about efficiency. – crackerplace Dec 22 '14 at 20:12

1 Answers1

-1

I was able to solve this.The program is working fine.Some issues in the way I copied the answer to the evaluation website.

Thanks.

crackerplace
  • 5,305
  • 8
  • 34
  • 42