TheAlgorithms-C-Plus-Plus/others/palindrome_of_number.cpp

28 lines
457 B
C++
Raw Normal View History

2019-02-10 14:40:29 +08:00
#include <algorithm>
2020-05-26 21:26:40 +08:00
#include <iostream>
2019-02-10 14:40:29 +08:00
#ifdef _MSC_VER
// Required to compile std::toString function using MSVC
#include <string>
#else
#include <cstring>
#endif
2020-05-26 21:26:40 +08:00
int main() {
int num;
std::cout << "Enter number = ";
std::cin >> num;
2020-05-26 21:26:40 +08:00
std::string s1 = std::to_string(num);
std::string s2 = s1;
2020-05-26 21:26:40 +08:00
reverse(s1.begin(), s1.end());
2020-05-26 21:26:40 +08:00
if (s1 == s2)
std::cout << "true";
else
std::cout << "false";
2020-05-26 21:26:40 +08:00
return 0;
}