473,395 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

output the longest palindrome

Write a Java program that prints the longest palindrome in an input file to standard output. A palindrome is a string whose reverse is the same as the original. Ignore case, whitespace, and punctuation in the input. If there are more than one palindrome of the maximum length, print the first one. Remove all space and punctuation and convert upper case to lower case in the output. If the input file contains:

Was it a rat I saw?

Your program prints:

% java Palindrome < inputfile
wasitaratisaw
Sep 14 '07 #1
4 5238
JosAH
11,448 Expert 8TB
Write a Java program that prints the longest palindrome in an input file to standard output. A palindrome is a string whose reverse is the same as the original. Ignore case, whitespace, and punctuation in the input. If there are more than one palindrome of the maximum length, print the first one. Remove all space and punctuation and convert upper case to lower case in the output. If the input file contains:

Was it a rat I saw?

Your program prints:

% java Palindrome < inputfile
wasitaratisaw
Should the program print the same if it were feeded;

Foo Was it a rat I saw bar?

kind regards,

Jos
Sep 14 '07 #2
Should the program print the same if it were feeded;

Foo Was it a rat I saw bar?

kind regards,

Jos
yes, it will still print " wasitaratisaw".
Sep 14 '07 #3
r035198x
13,262 8TB
Have you worked out your algorithm for it yet?
Sep 15 '07 #4
JosAH
11,448 Expert 8TB
An utterly naive algorithm would take O(n^2) steps: it checks all indexes j > i+1
whether substring s_i ... s_j is a palindrome or not. Cleverly in/decrementing
both index values would find larger palindromes first and cut off the search for
smaller palindromes; worst case it would still be a O(n^2) algorithm.

kind regards,

Jos
Sep 15 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Lorin Leone | last post by:
Can anyone help me modify the program so that it recognizes strings like "Anna" as palindromes. To make the program "case-insensitive." using the built-in C++ function "toupper". and so that it...
23
by: Amar Prakash Tripaithi | last post by:
Dan Hoey, who had recently graduated, wrote a C program to look for and construct the following beauty: A man, a plan, a caret, a ban, a myriad, a sum, a lac, a liar, a hoop, a pint, a catalpa,...
32
by: ramakrishnadeepak | last post by:
HI Everybody, I 've to submit a program on c.Can any one help me plz.........The problem is like this:: Write a program which computes the largest palindrome substring of a string. Input:...
4
by: outofmymind | last post by:
hi, im trying to solve the following question: Create a class responsible for determining whether a string is a palindrome. Show your test cases. Palindome mypal("bob"); ...
3
by: colinNeedsJavaHelp | last post by:
I am still having an exceptional amount of trouble with java. This is my new assignment, if anyone can help I would greatly appreciate it. I don't even know where to start. A word or phrase in...
2
by: Synapse | last post by:
aloha people! I need help in my java palindrome program. It's a 5-digit palindrome checker. The code below is running good but i got a few problems on it. If I enter 33633, 11211, 45554, it will...
2
by: xlilxmizzxinnocentx | last post by:
Hiya I was woundering if anyone could help me. A few weeks ago i started using vb 5.0 and now im trying to make a code to determine if a word is a palindrome or not. The code that i have tried dose...
20
by: Wabz | last post by:
Hello mates, Does anyone know how to write a function that tests if an integer is a palindrome in C language?
2
by: Kreators | last post by:
Hi everyone i'm newbie here in bytes and a newbie in programing i need your help! can you correct my program when my program compile its say Process completed. but when i put a Word and Run my...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.