0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-20 02:45:24 +00:00

P1206 [USACO1.2]回文平方数 Palindromic Squares

R40786577
This commit is contained in:
Baoshuo Ren 2020-10-29 21:41:34 +08:00 committed by Baoshuo Ren
parent 7678d77761
commit bba95b1588
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68
3 changed files with 72 additions and 0 deletions

66
problem/P1206/P1206.cpp Normal file
View File

@ -0,0 +1,66 @@
#include <bits/stdc++.h>
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;
}

BIN
problem/P1206/data/P1206_1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
problem/P1206/data/P1206_1.out (Stored with Git LFS) Normal file

Binary file not shown.