这一道题跟上一道十分的接近,没有什么可说的~
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 10000
void transtostr( int num, int base, char * numtostring )
{
int i = 0;
while( num > 0 )
{
*( numtostring + i ) = ( num % base ) + '0';
num /= base;
i++;
}
}
int isPalindromic( char * str, int len )
{
int i;
int isP = -1;
for( i = 0; i <= len / 2; i++ )
{
if( *( str + i ) != *( str + len - 1 - i ) )
{
isP = 0;
break;
}
}
return isP == 0 ? -1 : 1;
}
int main()
{
FILE * fin = freopen( "dualpal.in", "r", stdin );
FILE * fout = freopen( "dualpal.out", "w", stdout );
unsigned int startnum;
int amountneed;
int tmp_need = 0;
int tmp_base;
int tmp_num;
int tmp_time = 0;
char tmp_str[ N ] = {0};
int tmp_len;
fscanf( fin, "%d%u", &amountneed, &startnum );
for( tmp_num = startnum + 1; tmp_need < amountneed; tmp_num++ )
{
for( tmp_base = 2, tmp_time = 0; tmp_time < 2 && tmp_base <= 10; tmp_base++ )
{
memset( tmp_str, 0, N );
transtostr( tmp_num, tmp_base, tmp_str );
tmp_len = strlen( tmp_str );
if( isPalindromic( tmp_str, tmp_len ) == 1 )
{
tmp_time++;
}
}
if( tmp_time == 2 )
{
tmp_need++;
fprintf( fout, "%d\n", tmp_num );
}
}
return 0;
}