b = a/10000;
cout << b << endl;
c = (a%10000/1000);
cout << c << endl;
d = (a%1000/100);
cout << d << endl;
e = (a%100/10);
cout << e << endl;
f = a%10;
cout << f << endl;
if (b == 0) {cout << "That isn't a 5 digit number";}
else if (b != c){cout << "The first number doesn't match with the last";}
else if (f != d) {cout << "The secound number doesn't match with the fourth";}
else {cout << b << f << e << d << c << " is a paladrone";} return 0;
}
Name:
Anonymous2006-12-21 8:51
Do you mean palindrome, you cretin?
Name:
Anonymous2006-12-21 8:53
what for?
Name:
Anonymous2006-12-21 9:49
I would convert it to a string first and use a for loop to compare each symmetric pair of characters until they meet in middle (success) or don't match (fail). That way it wouldn't be constrained to just five digit palindromic numbers.
Name:
Anonymous2006-12-21 10:11
main = getLine >>= print . show . (\s -> s == reverse s)
Name:
Anonymous2006-12-21 10:12
actually "show" is unnecessary so
main = getLine >>= print . (\s -> s == reverse s)
Name:
Anonymous2006-12-21 10:20
My eyes, they bleed!
Don't convert the string into a number if you're going to extract the digits, and IF you're going to extract the digits from an int then don't use something as horribly slow as mod, and call cout once with many arguments instead of many times with one argument each time.
I would guess that the purpose of converting the string to a number is to removing any leading zeros.
Name:
Anonymous2006-12-23 4:12
>>9
You could do that with a "dropWhile (== '0')" though.
Name:
Anonymous2006-12-24 10:07
if(b) is better than (if b == 0)
Name:
Anonymous2006-12-24 10:52
lol wtf.
ALL of you are n00bs.
I could do this with a char array. WTF? 5 LONGS? You didn't even implement palindrome correctly. f = a%10; == 1234 if the number was 12345 queer.
Palindrome can be implemented in 4 fucking lines. 1 for variable initiation, 1 for cin, 2 for loops. Oh yeah, 2 more to display if it's a palindrome or not...
I sure hope 10 years from now, people who can't spell palindrome never get a job where I work.
Name:
Anonymous2006-12-24 10:54
btw 11. Every compiler automagically optimizes loops. Didn't know that did you?
while(b==true) == while ( b ) == while ( b >= 1 )
Name:
Anonymous2006-12-24 11:05
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
char aString[100];
bool bPalindrome = true;
cin>>aString;
for(int nPos = 0; 1 + 1 = 3; nPos++ )
if ( 1 ) bPalindrome = false;
if ( bPalindrome )
cout<<"Is a palindrome"<<endl;
else
cout<<"Is not a palindrome"<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Enjoy
Name:
Anonymous2006-12-24 12:12
>>14
and what if i want to test a 101 digit number if it's a palindrome?
lol C is lose and fail.
Name:
Anonymous2006-12-24 13:17
101
Is a palindrome
Press any key to continue . . .
You sir, are the fail.
Name:
Anonymous2006-12-24 13:22
10101010101010101010101010101010101010101010101010101010101010101010101010101010
10101010101010101010101010101010101010101010101010101010101010101010101010101010
101010101010101010101010101010101
Is a palindrome
Press any key to continue . . .
You again, are a fail.
I would like to see you copy a "101" digit number into a long :)
You again, are a fail.
Trying to be smart ass and using 64 bit precision numbers?
2^64 = 18446744073709551616. So you again, are a fail.
let me explain this to you, buddy. For you to have a "101" digit number, you would need: 2^328.87088139384887243916162351945 precision.
Can you show me a data type with 329 bit precision?
Name:
Anonymous2006-12-24 13:24
To show that the program works:
10101010101010101010101010101010101010101010101010101010101010101010101010101010
10101010101010101010101010101010101010101010101010101010101010101010101010101010
1010101010101010101010101010101011
Is not a palindrome
Press any key to continue . . .
To show that the program works:
10101010101010101010101010101010101010101010101010101010101010101010101010101010
10101010101010101010101010101010101010101010101010101010101010101010101010101010
1010101010101010101010101010101011
Is a palindrome
Press any key to continue . . .
>>17
Just goes to show that simply because something is made out of numerals, doesn't mean that you have to manage it as ints or longs or even bignums for that matter. Strings would do just as well, with a leading zero drop for the integral case.
Jeez, 4chan's /prog/ is like amateur hour all the time.
>>23 simply because something is made out of numerals, doesn't mean that you have to manage it as ints or longs or even bignums for that matter.
Obviously. However, given x bytes, the string representation will be able to hold values up to 10^x, whereas a pure binary representation can hold values up to 256^x; an immense difference in efficiency. In this case, for the sake of simplicity, (dynamically allocated) strings work best, but usually you should go with bignums when you need to work with arbitrarily large numbers.
>>25
If you get the number as a string (like from user input), yes, because then the algorithm is fairly trivial. However, if you get the number encoded as a dword or a bignum (from a function generating primes or whatever), there's probably a better way then just converting it to a string and using the string algorithm.
>>24
But then again, given modern computers (even in the presence of languages like Perl or Python or Javur), crawling over 256 kilos' worth of bytes each representing one digit in a base-10 number, to check whether it's a palindrome or not won't actually shatter your processor cycle budget.
And 262144 digits is one long fucking number. Even though it's only a tiny fraction of pi ;-)
b = a/10000;
c = (a%10000/1000);
d = (a%1000/100);
e = (a%100/10);
f = a%10;
if (b == 0) {cout << "That isn't a 5 digit number";}
else if (b != f){cout << "The first number doesn't match with the last";}
else if (c != e) {cout << "The secound number doesn't match with the fourth";}
else {cout << b << c << d << e << f << " is a paladrone";}
return 0;
}
Name:
Anonymous2006-12-27 23:37
perl -ple'$_=is.(\!\!($_-=reverse)&&" not")." a palindrome."'
Name:
Anonymous2006-12-28 10:06
perl -ple'$_=is.(\!\!($_-reverse)&&" not")." a palindrome."'
Name:
Anonymous2006-12-28 10:38
perl -ple'$_=is." not"x\!\!($_-reverse)." a palindrome."'
Name:
Anonymous2006-12-28 14:32
perl -ple'$_=is." not"x($_!=reverse)." a palindrome."'
and for >>37: perl -ple'$_=is.(/\D/?" not a number.":" not"x(($_*=1)!=reverse)." a palindrome.")'
Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy