Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Palindrome
- {
- public static void main(String[] args) {
- Deque<Character> deque = new Deque<Character>();
- char c;
- for (int i=0; !StdIn.isEmpty(); i++){
- deque.addFirst(StdIn.readChar());
- }
- if (deque.size()%2!=0){ //if its odd middle is never its complement, thus cant be palindrome
- StdOut.println("false");
- return;
- }
- while (deque.size()>1){
- char first=deque.removeFirst();
- char last=deque.removeLast();
- if (first == 'A'){
- if(last != 'T'){
- StdOut.println("false");
- return;
- }
- }
- else if (first == 'T'){
- if (last != 'A'){
- StdOut.println("false");
- return;
- }
- }
- else if (first == 'C'){
- if (last != 'G'){
- StdOut.println("false");
- return;
- }
- }
- else if (first == 'G'){
- if(last != 'C'){
- StdOut.println("false");
- return;
- }
- }
- else{
- StdOut.println("false");
- return;
- }
- }
- StdOut.println("true");
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement