check whether a palindrome can be formed from a given stirng

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2007
Posts: 20
Reputation: pavani2006 is an unknown quantity at this point 
Solved Threads: 0
pavani2006 pavani2006 is offline Offline
Newbie Poster

check whether a palindrome can be formed from a given stirng

 
0
  #1
May 20th, 2007
how can i check a given string to form a palindrome or not
for(i=0;i<str.length();i++)
{
if(str.charAt(i)==str1.charAt(i)
}
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 27
Reputation: jetru is an unknown quantity at this point 
Solved Threads: 0
jetru jetru is offline Offline
Light Poster

Re: check whether a palindrome can b eformed from a given stirng

 
0
  #2
May 20th, 2007
Hmm whats str1?
You have to compare the first letter and the last letter, then the second letter and the last but one letter and so on. So...think how we could go about doing that.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,619
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: check whether a palindrome can b eformed from a given stirng

 
0
  #3
May 20th, 2007
Assuming your palindrome logic ignores case, here is one solution:

  1. String str = "AB , ba";
  2. StringBuffer sb = new StringBuffer(str).reverse();
  3. String strRev = sb.toString();
  4. if(str.equalsIgnoreCase(strRev))
  5. System.out.println("Palindrome");
  6. else
  7. System.out.println("Not a Palindrome");
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 20
Reputation: pavani2006 is an unknown quantity at this point 
Solved Threads: 0
pavani2006 pavani2006 is offline Offline
Newbie Poster

Re: check whether a palindrome can b eformed from a given stirng

 
0
  #4
May 20th, 2007
sorry i am not trying to find the given string is palindrome or not,i am trying to find from a given string is it possible to form a palindrome or not?
suppose u input "oppa"
from this string it is possible to from a palindrome "pop"
but if u input a string"opai"
it is not possible to form a palindrome.that is what i want please if u know tell me
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,619
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: check whether a palindrome can b eformed from a given stirng

 
0
  #5
May 20th, 2007
You can start off by eliminating words which don't have a repeated character. This would help you in cutting down the processing. Then with the words which have at least a pair of repeating characters, try out various combinations of the character forming the word.

For eg. if your word is "sat", you can safely eliminate it since it doesn't have a repeating character. Now if the word in consideration is "sosa", generate various combinations of the characters forming the word which has at least a pair of repeating characters. Some examples would be "sos" and "sas". Of course yo have to keep in mind that single characters are by default palindromes.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: check whether a palindrome can b eformed from a given stirng

 
0
  #6
May 21st, 2007
Originally Posted by pavani2006 View Post
sorry i am not trying to find the given string is palindrome or not,i am trying to find from a given string is it possible to form a palindrome or not?
suppose u input "oppa"
from this string it is possible to from a palindrome "pop"
but if u input a string"opai"
it is not possible to form a palindrome.that is what i want please if u know tell me
what exactly are you trying to do???
"pop" is in no way a palindrome to "oppa".
a palindrome to "oppa" would be "appo".

you are here asking, is it possible to find a palindrome for "opai" with boolean 'false' as return.
well... the palindrome to "opai" is "iapo".

so, if I'm not mistaking, you're trying to find a word that is a palindrome and that can be formed with the letters used in the original (input)String?
Last edited by stultuske; May 21st, 2007 at 5:11 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 706
Reputation: stultuske is a jewel in the rough stultuske is a jewel in the rough stultuske is a jewel in the rough 
Solved Threads: 84
stultuske's Avatar
stultuske stultuske is offline Offline
Master Poster

Re: check whether a palindrome can b eformed from a given stirng

 
0
  #7
May 21st, 2007
Originally Posted by stultuske View Post
well... the palindrome to "opai" is "iapo".
brrrr... by my last post you can propably see I didn't sleep to well ...
opai is no palindrome, excuse me for the mistake
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 20
Reputation: pavani2006 is an unknown quantity at this point 
Solved Threads: 0
pavani2006 pavani2006 is offline Offline
Newbie Poster

Re: check whether a palindrome can b eformed from a given stirng

 
0
  #8
May 21st, 2007
Originally Posted by stultuske View Post
what exactly are you trying to do???
"pop" is in no way a palindrome to "oppa".
a palindrome to "oppa" would be "appo".

you are here asking, is it possible to find a palindrome for "opai" with boolean 'false' as return.
well... the palindrome to "opai" is "iapo".

so, if I'm not mistaking, you're trying to find a word that is a palindrome and that can be formed with the letters used in the original (input)String?
i am not trying to find i am trying to form a palindrome fron the letters of the given string
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,619
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: check whether a palindrome can be formed from a given stirng

 
0
  #9
May 21st, 2007
> i am not trying to find i am trying to form a palindrome fron the letters of the given string
Use the approach suggested by me in my previous post.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 56
Reputation: staneja is an unknown quantity at this point 
Solved Threads: 1
staneja's Avatar
staneja staneja is offline Offline
Junior Poster in Training

Re: check whether a palindrome can be formed from a given stirng

 
0
  #10
May 25th, 2007
hey i think what you can do is you find the frequency of characters in a word
Like ""madam" is having 2 m and 2 "a" and 1"d" so u can make pallindronme for it

Its just a logic that u can think abt...Hope it will help u in 1 way or another
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC