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
hai i am prasanna.I am MCA 2009 fresher.tell me about certifications.which certification helps me to improve my carrier and to get a technically oriented job ,which certification helps to get job faster.
iam confused among testing ,.net and java. can anybody help me.
hi, all this is shoba m.c.a . i have learned abap but no oppurtunities right now as fresher , right now i want to learn any course on demand any one pls suggest me good course and institute in hyderabad
how can i create report in abap to insert data in table pa0002 using insert command
what are the things i had to say in personal introduction in hr round mail me to prasanna.1867@rediff.com
what is meant by life cycle of a business
design a counter with the following repeated binary sequence: 0, 1, 2, 3, 4, 5, 6, 7, 8 using JK Flip Flop.
Plz sent me in .net 2.0 interview Question & answers?
sample and simple coding where we get?
Which language they use during interview?
Difference between debugging, running, executing of an application
< No Frames > tag is used for
Please forward important interview and basic questions in VB6 on my email id: usneha_16@yahoo.co.in
Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 2 numbers. Find the missing numbers.
diffrence between oracle apps , .NET , SAP