0
Can anyone write the shortest code for a palindrome ? Also try and do it for words like HANNAH .
Time constraint is 1s only and palindrome is a number that is same from front to back.
5 ответов
+ 7
I'm trying to find a shorter version... But if you use python, the code will just be a one liner...
+ 6
// C++ Code.
// Time taken for 52 letter string - 0.04s
// Number of lines - 11
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string data, data2;
getline(cin,data);
data2 = data;
reverse(data2.begin(),data2.end());
if(data2 == data) cout<<"Yes";
else cout<<"No";
}
+ 4
// Python Code.
// Time taken for 52 letter string - 0.00s
// Number of lines - 2
a = raw_input()
print(str(a)==str(a)[::-1])
- 2
print((lambda a:a==a[::-1])(input()))