Are you enough smart?
#include<iostream>
#include<cstring>
#include<string.h>
using namespace std;
int main()
{
char phrase[100];
start:
cout << "Insert phrase:" << endl;
cin.getline(phrase,100, '\n');
int x=strlen(phrase);
char phrase2[x];
int j=0;
for (int n=0; n<=x; n++) {
if (phrase[n]!=' ') {phrase2[j]=phrase[n]; j++;}
}
char reverse[x];
j=j-2;
for (int n=0; n<=x; n++) {
reverse[n]=phrase2[j];
j--;}
if (strcmp(reverse,phrase2)==0)
cout << "Palindromic";
else
cout << "Not palindromic";
cout << endl;
cout << reverse; //WHY REVERS ARRAY IS FUCKED UP?!
return 0;
}
INPUT:
amica di pirati vede ed evita ripida cima
#include <algorithm>
#include <string>
#include <iostream>
#include <cctype>
int main() {
std::string phrase;
std::cout << "Enter pharase: ";
std::getline(std::cin, phrase);
std::cout << "" << std::endl;
phrase.erase(std::remove_if(phrase.begin(), phrase.end(), ::isspace),phrase.end());
std::string phrase2 = phrase;
std::reverse(phrase2.begin(), phrase2.end());
if (phrase == phrase2) {
std::cout << "PALINDROME" << std::endl;
} else {
std::cout << "NOT A PALINDROME" << std::endl;
}
return 0;
}
You're a fucking retard OP.
>buffer overflow
back to java pajeet
input="im gay and also gay y a g osla dna yag mi"
print("PALINDROME" if input.replace(" ","")==input.replace(" ","")[::-1] else "NOT PALINDROME"
>>59562521
>char phrase2[x];
x isn't a constant expression dumbass
>>59562521
>C++
>uses C strings anyways
>buffer overflows everywhere
kys, OP.
>>59563308
Python's syntax to reverse lists is pretty retarded
>>59562521
Thank you for a decent post that isn't shilling, senpai
>>59563340
because using reverse slicing like that is actually pretty retardedlist(reversed(input)) will work much better
>>59563340
python's everything is fucking retarded
polluted global namespace with retarded functions like len() when the language is OO, statements for literally everything under the sun, no real lambdas.
why anyone uses it is beyond me.
>>59563226
>creating a copy#include <algorithm>
#include <string>
#include <iostream>
#include <cctype>
int main()
{
std::string p;
std::cout << "Enter phrase: ";
std::getline(std::cin, p);
std::cout << std::endl;
phrase.erase(std::remove_if(p.begin(), p.end(), ::isspace), p.end());
if(std::equal(p(), p.end() + p.size()/2, p.rbegin()))
{
std::cout << "PALINDROME" << std::endl;
}
else
{
std::cout << "NOT A PALINDROME" << std::endl;
}
return 0;
}
>>59562521
>no code box
didn't read
>>59563452
>p.begin()
FTFM
>>59562521
Surely you can, /g/?
>>59563572
largest possible sum: 999 + 999 = 1998
so the largest possible is obviously: 1991
>>59563627
Oh sorry, it says product not sum.
Can't do that in my head anymore.
>>59563572
Apparently I can
>>59563676
So can I, give me a minute.
>having an account
Why?
>>59563340
ya use django1.5 way better for python
>>59563572
>>59563676# Generate all palindromic products of two 3-digit numbers.
for i in range(10001, 1000000):
if str(i) == str(i)[::-1]:
for m in range(100, 1000)[::-1]:
if i % m == 0 and 100 <= i / m <= 999:
print(i, '=', int(i / m), 'x', m)
break
906609
>>59563804
>>having an account
>Why?
So that now, three years after solving it, I can go back to see if I solved it.
>>59564055
>he doesn't have redundant backups of every piece of code minor or not he's ever written
>>59562521
>string.h
>using namespace std;
>char phrase2[x]
>char reverse[x]
REEEEEEEEEEE