why should I write such a program?
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Take the string and spell it in reverse. Compare the two strings, if they match you got a palindrome. Now show us some code!
vegaseat
DaniWeb's Hypocrite
5,986 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
try this logic...
You know a word isn't a palindrome if it's an odd number of characters.
"dad" is a palindrome.
Rashakil Fol
Super Senior Demiposter
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
"dad" is a palindrome.
depends on the definition used. Some might say it's not a palindrome because the a isn't the same as another letter in the word (even though being of course identical to itself).
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
this should work...
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
const int NULA = 0;
string a, b;
char buff[1026];
int main (void) {
while( scanf( "\n%s", buff ) == 1 ) {
b = a = buff;
reverse( b.begin(), b.end() );
if( a == b ) printf( "PALINDROM\n" );
else printf( "NOT A PALINDROM\n" );
}
return NULA;
}
1. Don't be foolish enough to do someone's homeworkand at the very least keep it consistent to one language.
2.If you feel inclined to do ppl's homework then by all means do so but don't bother posting it! That way you're happy, I'm happy everyone is happy. :rolleyes:
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
well, if I were a teacher having to grade that I'd fail it immediately anyway.
Ugliest mix of C and C++ I've ever seen, global variables, very bad variable naming, etc. etc.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
well, if I were a teacher having to grade that I'd fail it immediately anyway.
Ugliest mix of C and C++ I've ever seen, global variables, very bad variable naming, etc. etc.
Looks like our friend brahle uses cstdio rather than iostream because of the much smaller executable it produces. Maybe it is bad habit to mix C and C++, but then C++ is tolerant of C. I consider that one strength of C++ anytime. NULA (must be Croation for NULL) and return NULA is optional with C++ however.
bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
Doesn't matter if it's tolerant of old style code, it's there for backwards compatibility only.
I can also run a 16 bit application on XP, doesn't mean I should make them just because they're easier to write...
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337