From bba95b1588920e8771ca48fff4eedcc0d1846e9f Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Thu, 29 Oct 2020 21:41:34 +0800 Subject: [PATCH] =?UTF-8?q?P1206=20[USACO1.2]=E5=9B=9E=E6=96=87=E5=B9=B3?= =?UTF-8?q?=E6=96=B9=E6=95=B0=20Palindromic=20Squares?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R40786577 --- problem/P1206/P1206.cpp | 66 ++++++++++++++++++++++++++++++++++ problem/P1206/data/P1206_1.in | 3 ++ problem/P1206/data/P1206_1.out | 3 ++ 3 files changed, 72 insertions(+) create mode 100644 problem/P1206/P1206.cpp create mode 100644 problem/P1206/data/P1206_1.in create mode 100644 problem/P1206/data/P1206_1.out diff --git a/problem/P1206/P1206.cpp b/problem/P1206/P1206.cpp new file mode 100644 index 00000000..12daf4c1 --- /dev/null +++ b/problem/P1206/P1206.cpp @@ -0,0 +1,66 @@ +#include + +using namespace std; + +class node { + private: + char c(int x) { + if (0 <= x && x <= 9) { + return x + '0'; + } + return x - 10 + 'A'; + } + int len; + int nums[20]; + + public: + node() { + len = 0; + } + node(int x, int b) { + len = 0; + while (x) { + nums[len] = x % b; + x /= b; + len++; + } + } + + int& operator[](int x) { + return nums[x]; + } + + const char* c_str() { + string s; + for (int i = len - 1; i >= 0; i--) { + s.push_back(c(nums[i])); + } + return s.c_str(); + } + string print() { + for (int i = len - 1; i >= 0; i--) { + cout << c(nums[i]); + } + return ""; + } + bool check() { + for (int i = 0; i < len; i++) { + if (nums[i] != nums[len - i - 1]) { + return false; + } + } + return true; + } +}; + +int main() { + int b; + cin >> b; + for (int i = 1; i <= 300; i++) { + node t = node(i * i, b); + if (t.check()) { + cout << node(i, b).print() << ' ' << t.print() << endl; + } + } + return 0; +} diff --git a/problem/P1206/data/P1206_1.in b/problem/P1206/data/P1206_1.in new file mode 100644 index 00000000..adccc0fc --- /dev/null +++ b/problem/P1206/data/P1206_1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a44dc15364204a80fe80e9039455cc1608281820fe2b24f1e5233ade6af1dd5 +size 2 diff --git a/problem/P1206/data/P1206_1.out b/problem/P1206/data/P1206_1.out new file mode 100644 index 00000000..b9e227c9 --- /dev/null +++ b/problem/P1206/data/P1206_1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88a4505153f131552de3d45243b18c66b18bf159dbf6a22f6ebaf92a3305f2d2 +size 93