/*
ID: america6
PROG: dualpal
LANG: C++11
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string trans(int base, int num) {
string tn;
while (num) {
int d = num%base;
if (d >= 0 && d <= 9) {
tn.insert(tn.begin(), '0'+d);
}
else if (d >= 10) {
tn.insert(tn.begin(), 'A'+d-10);
}
num/=base;
}
return tn;
}
bool pal(string tn) {
int i = 0, j = tn.size()-1;
while (i < j) {
if (tn[i] != tn[j]) {
return false;
}
i++;
j--;
}
return true;
}
int main(int argc, char const *argv[]) {
ofstream fout ("dualpal.out");
ifstream fin ("dualpal.in");
int n, s;
fin >> n >> s;
for (int ni = 1; ni <= n; ) {
++s;
int t = 0;
for (int i = 2; i <= 10 && t < 2; ++i) {
if (pal(trans(i, s))) {
t++;
}
}
if (t >= 2) {
fout << s << endl;
ni++;
}
}
return 0;
}
Dual Palindromes
最新推荐文章于 2022-04-26 20:19:35 发布