javapattern-matchingrosalind

Rosalind Pattern Matching Java Not Accepted


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();
    }
}

Solution

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