进制回文数
1 #include <stdio.h> 2 bool huiwen(char a[], int n){ 3 4 int i, j; 5 i = 0; j = n - 1; 6 7 while (i < j){ 8 if (a[i] != a[j]) 9 return false; 10 i++; 11 j--; 12 } 13 14 return true; 15 } 16 17 int main(){ 18 char buffer[1001]; 19 int a; 20 int temp; 21 int counter = 0; 22 int i; 23 while (scanf("%d", &a) != EOF){ 24 int b = a; 25 for ( i = 2; i <= 16; i++){ 26 b = a; 27 counter = 0; 28 while (b){ 29 temp = b % i; 30 b /= i; 31 if (temp >= 10){ 32 buffer[counter] = temp - 10 + 'A'; 33 } 34 else{ 35 buffer[counter] = temp + '0'; 36 } 37 counter++; 38 } 39 40 //printf("i = %d, counter = %d\n", i, counter); 41 if (huiwen(buffer, counter)){ 42 break; 43 } 44 45 }//end for 46 47 if (i >= 17){ 48 printf("No\n"); 49 } 50 else{ 51 printf("Yes\n"); 52 } 53 } 54 55 }