From 7387683604392c2b145a5352ae6c7c10af9b01f5 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 26 May 2024 14:43:39 +0800 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=9B=9E=E6=96=87=E6=95=B0+=E8=BD=AC=E6=8D=A2=E5=85=AB?= =?UTF-8?q?=E8=BF=9B=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- palindrome-number/main.cc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 palindrome-number/main.cc diff --git a/palindrome-number/main.cc b/palindrome-number/main.cc new file mode 100644 index 0000000..bf78f2c --- /dev/null +++ b/palindrome-number/main.cc @@ -0,0 +1,29 @@ +#include +#include +using namespace std; + +string dec2oct(int dec) { + string buffer; + while (dec) { + buffer = char(dec % 8 + '0') + buffer; + dec /= 8; + } + return buffer; +} + +bool is_palindrome_number(string val) { + string reversed; + for (int i = val.size() - 1; i >= 0; i--) + reversed += val[i]; + return reversed == val; +} + +int main() { + int n; + cin >> n; + int sqaure_n = sqrt(n); + for (int i = 1; i <= sqaure_n; i++) { + if (is_palindrome_number(dec2oct(i * i))) + cout << i * i << " "; + } +}