In Bioinformatics, a DNA sequence is made up of a
combination of 4 characters, namely “A,C,G,T”. A
subsequence of a given sequence of characters a0, a1, …an-
1, is any subset of the characters taken in order, of the
form ai0 , ai1 ,…..aik-1 where 0 ≤ i0 <i1….< ik-1 ≤ n-1.
For example in the sequence “A,C,G,T,G,T,C,A,A,A,A,T,C,G”,
we can have subsequences “A,G,T”, “A,C,A,A” and many more.
A subsequence is palindromic if it is the same whether read
left to right or right to left. For instance, the
sequence “A,C,G,T,G,T,C,A,A,A,A,T,C,G”, has many
palindromic subsequences, including “A,C,G,C,A”
and “A,A,A,A” (on the other hand, the subsequence “A,C,T”
is not palindromic). Devise an algorithm (using dynamic
programming) that takes a sequence of characters X[0 … n-1]
from the alphabet set (A,C,G,T) and returns the (length of
the) longest palindromic subsequence. Implement the
algorithm in an appropriate language.
Answer Posted / pragnesh
import java.io.*;
import java.util.*;
public class p3{
public static void main(String[] args) throws
FileNotFoundException{
Scanner inFile = new Scanner(new FileReader("words.txt"));
String s;
String temp, tempRev="";
while(inFile.hasNext()){
s=inFile.nextLine();
temp=s;
temp = temp.replace("?","");
temp = temp.replace(".","");
temp = temp.replace(",","");
temp = temp.replace(":","");
temp = temp.replace("\"","");
temp = temp.replace(" ","");
for(int x=temp.length()-1;x>=0;x--)
tempRev = tempRev + temp.charAt(x);
if(temp.equalsIgnoreCase(tempRev))
System.out.println(s + " is a palindrome");
else
System.out.println(s + " is not a palindrome");
tempRev="";
}
inFile.close();
}
}
maybe you could adapt that to c++
Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
hi i m deepak my shedule for NIC pi is 17 Apr please contact me if anybody has interview on same day or give me some idea who have faced
hi This is radhika.Can anyone help me to know the question papers of NATIONAL INFORMATICS CENTRE for the post of scientific officer/engineer? if anyone know plz tell me question paper pattern
3 members in a pf.how we read 3 members without using ovrdbf.using rg pgms....
What is the difference between COM and CORBA?
How to call dll API sub routine in VB Form.
how do u handle table control inbdc explain the process in steps iwant the answer in urgent please forward this even i know how to explain there
what is dot net framework
I am taking the bmc control m/enterprise manager 7.0 scheduling test and just wanted to see what kind of questions they would ask or if anyone has taken the test and how long it is for how many questions?
How do you pass variables forwrd to future CECI sessions
Hi..Am done with my Masters recently..Am planning to learn TIBCO.. could anyone suggest me about how the job market will be and Is there any course necessary to learn prior to Tibco..i mean any prerequisite. I dnt have any knowledge on PL/SQL thats it... Plz suggest me in a best way...
Given a set. Write the pseudo code to get all the subsets for the given set. Eg. Input : {1,2} Output : (),(1),(2),(1,2)
How will you prove that java swing is multithreaded?
through which algorithm does the garbage collector works? how the garbage collector will understand that the object will going to be deleted?
In an customer exit (include Z) program, only the last record is getting fetched. The exit is getting called after pressing save button. What to write for fetching the first record ? Before saved to a SAP table how can i call all these records in an itab in the exit ?
what is throws keyword