# 1.2.5 Dual Palindromes 双重回文数

1.2.5 Dual Palindromes 双重回文数

N行, 每行一个满足上述要求的数，并按从小到大的顺序输出.

``````3 25
``````

``````26
27
28
``````

``````#include<stdio.h>
#include<string.h>
int change(int n,int base,char str[])
{
int i=0;
while(n){
str[i]=n%base;
if(str[i]<10)
str[i]+='0';
else
str[i]=str[i]-10+'A';
i++;
n=n/base;
}
str[i]=0;
return 1;
}
int judge(char str[])
{
int n=strlen(str),i;
for(i=0;i<n/2;i++)
if(str[i]!=str[n-i-1])
return 0;
return 1;
}
int main()
{
int n,s;
while(scanf("%d %d",&n,&s)==2){
int i,count=0;
char str[1000]={0};
while(count<n){
int sum=0;
s++;
for(i=2;i<=10;i++)
if(change(s,i,str)&&judge(str)&&sum++>=1){
printf("%d\n",s);
count++;
break;
}
}
}
return 0;
}``````

``````#include<iostream>
#include<stdio.h>
#include<memory.h>
#include<cstring>
using namespace std;
int pan(int n,int k)
{
int a[30],i=0;
while(n)
{
a[i++]=n%k;
n/=k;
}
for(int j=0;j<i/2;j++)
if(a[j]!=a[i-j-1])return 0;
return 1;
}
int main()
{
int a,b;
cin>>a>>b;
int k=0;
for(int i=b+1;;i++)
{
int s=0;
for(int j=2;j<11;j++)
if(pan(i,j))
{
s++;
if(s==2)
{
k++;
break;
}
}
if(k>a)break;
if(s==2)cout<<i<<endl;
}
return 0;
}
``````