不做解釋,有心看我上一篇就好。
完全抄上一篇。
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int n, t;
char c[21] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' };
bool is_pal(string s) {
int size = s.size();
for (int i = 0, j = s.size() - 1; i < j; i++, j--){
if (s[i] != s[size - i - 1]) return false;
}
return true;
}
string reverse(string s) {
string res = "";
for (int i = 0; i < s.size(); i++){
res += s[s.size() - i - 1];
}
return res;
}
string change_base(int n, int base){
string res = "";
while (n != 0) {
int tmp = n%base;
res += c[tmp];
n /= base;
}
return res;
}
int main(){
ifstream fin("dualpal.in");
ofstream fout("dualpal.out");
fin >> n >> t;
int c = 0;
while (c != n) {
t++;
int judge = 0;
for (int j = 2; j <= 10; j++){
if (is_pal(change_base(t, j))) {
judge++;
if (judge == 2) {
fout << t << endl;
c++;
break;
}
}
}
}
return 0;
}