Largest Palindrome

R

ramakrishnadeepak

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:
The input is the string whose largest palindrome substring should be
found.

Output:
The output displays the largest palindrome substring.

Sample Input:
Enter the string: Habitat

Sample Output:
The longest palindrome substring of Habitat is: tat
 
R

Richard Bos

(e-mail address removed) wrote:

[ Snip whole homework assignment written by a teacher who is clearly
better at non-d00d English than his pupils. ]

And your work so far is? Surely you don't expect us to do your homework
for you?

Richard
 
M

MQ

Richard said:
(e-mail address removed) wrote:

[ Snip whole homework assignment written by a teacher who is clearly
better at non-d00d English than his pupils. ]

And your work so far is? Surely you don't expect us to do your homework
for you?

Richard

This really annoys me. As if there isn't enough incompetent IT
professionals out there...
 
O

osmium

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:
The input is the string whose largest palindrome substring should be
found.

Output:
The output displays the largest palindrome substring.

Sample Input:
Enter the string: Habitat

Sample Output:
The longest palindrome substring of Habitat is: tat

Note that the first letter of a palindrome is the same as the last letter.
Proceed from there.
 
F

Frederick Gotham

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:
The input is the string whose largest palindrome substring should be
found.

Output:
The output displays the largest palindrome substring.

Sample Input:
Enter the string: Habitat

Sample Output:
The longest palindrome substring of Habitat is: tat


I had this assignment a few years ago, got an A! Here's the exact code copy-
pasted. The code is perfect, fully-portable... just need to hand it in!

#include
"stdio.h"

#include
"string.h"

void main(int)
{
char[64] buffer;

scanf(STRING,buffer);

int * const p;

while
{
p = permute(buffer, buffer + len);
} do( p > --p );


printf(p);
}


Hope that helps, always love to help out a fellow student : ) !
 
A

Andrew Poelstra

I had this assignment a few years ago, got an A! Here's the exact code copy-
pasted. The code is perfect, fully-portable... just need to hand it in!

#include
"stdio.h"

#include
"string.h"

void main(int)
{
char[64] buffer;

scanf(STRING,buffer);

int * const p;

while
{
p = permute(buffer, buffer + len);
} do( p > --p );

printf(p);
}

Hope that helps, always love to help out a fellow student : ) !

I laughed out loud at that one. :)
 
P

pete

Andrew said:
I had this assignment a few years ago, got an A!
Here's the exact code copy-
pasted. The code is perfect, fully-portable...
just need to hand it in!

#include
"stdio.h"

#include
"string.h"

void main(int)
{
char[64] buffer;

scanf(STRING,buffer);

int * const p;

while
{
p = permute(buffer, buffer + len);
} do( p > --p );

printf(p);
}

Hope that helps, always love to help out a fellow student : ) !

I laughed out loud at that one. :)

Nobody is entitled to make any serious decisions
based on "code tested" and "code not tested" labels
on posted code.

Which is why
I'm not a fan of "code tested" and "code not tested" labels.

No criticism of Frederick Gotham is intended here.
 
L

lovecreatesbeauty

Andrew said:
I laughed out loud at that one. :)

I have written a function to identify a whole as palindromic or not. My
function knows this one is a palindrome:

A man, a plan, a canal - Panama!

To determine whether the following one is a palindrome will be more
difficult than the last one.

abcdefghijklmnopqrstuvwxyz0123456789 A man, a plan, a canal - Panama!

(please do not laugh at the following function:), but comments are
welcome!)

/*palindrome.c*/

#include <stddef.h>
#include <string.h>
#include <ctype.h>

/*determine a sentence if it is a palindrome. s: the string to be
determined. return 1 for identifying a successful palindrome, 0 for
not. - jhl, Jul 2006*/

int palindrome(const char *s)
{
int pln = 1;
const char *left, *right;

if (s != NULL){
left = s;
right = s + strlen(s) - 1;
while (left < right){
if (!isalnum(*left)){
++left;
continue;
}
if (!isalnum(*right)){
--right;
continue;
}

if (toupper(*left) == *right || tolower(*left) == *right){
++left;
--right;
continue;
} else {
pln = 0; /*charaters occur mismatched, it is not palindrome*/
break;
}
}
}

return pln;
}

/* test */
#include <stdio.h>
int main()
{
printf("%d\n", palindrome("Madam, I'm Adam!"));
printf("%d\n", palindrome("A man, a plan, a canal - Panama!"));
printf("%d\n", palindrome("Able was I, ere I saw Elba."));
printf("%d\n", palindrome("Ana voli Milovana"));
return 0;
}

$ cc -ansi -pedantic -Wall -W palindrome.c
$ ./a.out
1
1
1
1
$

lovecreatesbeauty
 
R

Richard Heathfield

lovecreatesbeauty said:
I have written a function to identify a whole as palindromic or not.

Is it that time already? Here we go, then:

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define p void
#define a sizeof
#define l char
#define i return
#define n int
#define d size_t
#define r if
#define o while
#define m else
#define e for
#define ob putchar
#define fu strlen
#define sc isalpha
#define at tolower
#define ed fgets
#define cp printf
#define ro strchr
#define gr main
#define am stdin
n c(l*s){n k=
0;r(s){d x
=fu (s)
;r(x>1)
{l*t=s,
*u=s+x-
1;k=1;o
(k&&t<u
){r(sc(
*t)){r(
sc(*u))

{r(at(
*t)!=at(
*u) ){k
=0; }m{
++t;--u;}}m{--
u;}}m{++t;}}}}
i k ;}n
gr( p){
l b [01
<<1 <<1

<<1
<<1
<<1
<<1
<<1
<<1
<<1
],*
z,*s=" adeil"
"mnoprst.\n";

n f[]={00,01<<1
<<1,(1<<1<<1<<1
)|(
1<<
1)|
1},
v[]
={0
,(1<<1<<1)|(1<<
1)|1,1<<1<<1<<1


,(1 <<1
<<01 <<1
)|(01 <<1
<<1 )} ,q[
]={ (1 <<1
)&1 ,1 <<1,(1 << 1<<
1<< 1) |1,
1<< 01<<1

<<1 )|(
1<< 1>>
1), 1<<
1<< 1,(
1<< 1<<
1)| (01
<<1 )|1
,01 <<1
,(1<<1<<1<<1


)|(1<<01),1
<<1 <<1
<<1 ,(1
<<1 <<1
)|1 <<1
,(1 <<1
)|1,(1<<
1<< 1<<
1)| (01
<<1 <<1
)|1 ,(1
<<1 <<1


<<1)|(1<<
1<< 1)|
(01 <<1
)}; d y
;o( ed(
b,a (b)
,am )){
{z= ro(
b,1 *1*
'\n');}if(

z){ *z=
00;} {cp(
"%s", b);}e
(y=0;1 *y<a f
/a( 1[f ]); y++
)ob (y[f][ s])
;r( !c(b ))e
(y= 0; y<a
v/a 1[v
];y ++)


ob(01*y[v]);e
(y=0/1*1/1<<1<<1
<<1
;y<
a q
/a 1[q]
;y++)ob
(y[
q][
s])
;}i 0>>1<<0>>1<<
1*1/(1<<1<<01);}
 
F

Flash Gordon

lovecreatesbeauty wrote:

if (toupper(*left) == *right || tolower(*left) == *right){

I would replace the above with either
if (toupper(*left) == toupper(*right)){
or
if (tolower(*left) == tolower(*right)){

depending on my mood. Also there is the debate about whether left and
right should be pointers to unsigned char or whether you should cast the
dereferenced value to unsigned char. Personally, I would make them
pointers to unsigned char for this function.

<snip>
 
L

lovecreatesbeauty

Flash said:
I would replace the above with either
if (toupper(*left) == toupper(*right)){
or
if (tolower(*left) == tolower(*right)){

I expect this one may save one additional function call.

if (toupper(*left) == *right || tolower(*left) == *right){
depending on my mood. Also there is the debate about whether left and
right should be pointers to unsigned char or whether you should cast the
dereferenced value to unsigned char. Personally, I would make them
pointers to unsigned char for this function.

int palindrome(const char *s)
{
/*...*/
left = s;
right = s + strlen(s) - 1;
/*...*/

left and right is the same type as parameter s's, i.e. char *, and char
may be signed or unsigned, it is undefined. The sign flag does not
matter, does it?

lovecreatesbeauty
 
L

lovecreatesbeauty

Richard said:
lovecreatesbeauty said:


Is it that time already? Here we go, then:

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define p void
#define a sizeof
#define l char
#define i return
#define n int
<snip>

I just meant a whole string (sentence), not a sub-string, not a file.
But you can read your files one by one into a string variable (it is
your duty) then invoke my function (through the interface), it may
works :)

lovecreatesbeauty
 
F

Flash Gordon

lovecreatesbeauty said:
I expect this one may save one additional function call.

if (toupper(*left) == *right || tolower(*left) == *right){

Or if toupper and tolower are implemented as efficient macros your
method might be slower. I merely expressed my preference, which IMHO
shows the intent better) I did not say your code was wrong.
int palindrome(const char *s)
{
/*...*/
left = s;
right = s + strlen(s) - 1;
/*...*/

left and right is the same type as parameter s's, i.e. char *, and char
may be signed or unsigned, it is undefined.

No, it's implementation defined.
> The sign flag does not
matter, does it?

It does matter. See the recent exceedingly long thread titled:
What's the deal with the "toupper" family?
for all the gory details.
 
O

Old Wolf

lovecreatesbeauty wrote:

[some lines snipped]
int palindrome(const char *s)
{
int pln = 1;
const char *left, *right;

if (s != NULL){
while (FOO){
BAZ;
if (BAR){
++left;
--right;
continue;
} else {
pln = 0; /*charaters occur mismatched, it is not palindrome*/
break;
}
}
}

return pln;
}

Question for Richard -- how can you prefer this to:

int palindrome(const char *s)
{
const char *left, *right;

if (s == NULL)
return 1;

for (;;)
{
if (!FOO)
return 1;

BAZ;

if (!BAR)
return 0;

++left;
--right;
}
}

Specifically, are you comfortable with most of the function
being at an extra level of indent; and all those continues
and breaks?
 
L

lovecreatesbeauty

Richard said:
Old Wolf said:


<ghastly code snipped>

I don't. I think they're both ghastly.

Hello Old Wolf and Richard, could you write some graceful versions of
palindromic function, or people may think you were / are on
windbaggery, they may be eager to read that code from both you. My
ghastly code quoted below first:

/*palindrome.c*/
#include <stddef.h>
#include <string.h>
#include <ctype.h>

/*determine a sentence if it is a palindrome. s: the string to be
determined. return 1 for identifying a successful palindrome, 0 for
not. - jhl, Jul 2006*/

int palindrome(const char *s){
int pln = 1;
const char *left, *right;

if (s != NULL){
left = s;
right = s + strlen(s) - 1;
while (left < right){
if (!isalnum(*left)){
++left;
continue;
}
if (!isalnum(*right)){
--right;
continue;
}

if (toupper(*left) == *right || tolower(*left) == *right){
++left;
--right;
continue;
} else {
/*charaters occur mismatched, the string is not a palindrome*/
pln = 0;
break;
}
}
}

return pln;
}
 
R

Richard Heathfield

lovecreatesbeauty said:
Hello Old Wolf and Richard, could you write some graceful versions of
palindromic function,

Yes, I could.
or people may think you were / are on windbaggery,

That's great psychology. Why don't you just say something rude about my
mother?
 
J

Juuso Hukkanen

Hello Old Wolf and Richard, could you write some graceful versions of
palindromic function, or people may think you were / are on
windbaggery, they may be eager to read that code from both you. My
ghastly code quoted below first:
<OT>
Yeah, and please do not forget to write donation to public domain
clause so that ramakrishnadeepak and I can leech copies with good
conscience; Ramakrishna to teacher and I as a raw material for
t3d_find_barray_Rbarray_SUBSTRING_n_LONGEST_PALINDROME()
(note expressiveness in function name)

Just kidding, at least don't do it for me :) I see people sending all
the time all kinds of sleazy psycho enhanced challenges formulated in
couple simple words that take hours or even days to execute. For
example when I recently posted a data-mining algorithm link to
requester who wanted data-mining algorithms in C (who had gotten
nothing from anyone else), few days later there was "Your Uncle"
asking me to prove that I understand or not understand the algorithms
in a (good) link-page I gave...
I'd love to hear anything you have to say about this topic. I believe it has forensic dimensions. bfx
</snip>

Ehh, dream on 'Uncle'.


Juuso Hukkanen
www.tele3d.com
(to reply by e-mail set addresses month and year to correct)
"t3d programming language" and the structure of t3d function prototype
are trademarks of Juuso Hukkanen. (Currently discussing the
transfer of those to a major charity organization).
</OT>
 
N

Nick Keighley

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:
The input is the string whose largest palindrome substring should be
found.

Output:
The output displays the largest palindrome substring.

Sample Input:
Enter the string: Habitat

Sample Output:
The longest palindrome substring of Habitat is: tat

is it september already?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top