Skip to content

Instantly share code, notes, and snippets.

@iporsut
Created August 15, 2012 17:37
Show Gist options
  • Save iporsut/3361849 to your computer and use it in GitHub Desktop.
Save iporsut/3361849 to your computer and use it in GitHub Desktop.
ZOJ 1078 : Palindrom Numbers
#include <stdio.h>
int base[16];
int palindrom(int len) {
int i,j;
for(i = 0,j = len-1; i < j; ++i, --j) {
if (base[i] != base[j])
return 0;
}
return 1;
}
int convert_base(int num, int b) {
int len = 0;
while(num != 0) {
base[len] = (num%b);
num /= b;
len++;
}
return len;
}
int main() {
int num, i, has;
scanf("%d", &num);
while(num != 0) {
has = 0;
for(i = 2; i <= 16; ++i) {
if (palindrom(convert_base(num, i))) {
has++;
if(has == 1)
printf("Number %d is palindrom in basis %d", num,i);
else
printf(" %d", i);
}
}
if (!has) {
printf("Number %d is not a palindrom", num);
}
printf("\n");
scanf("%d", &num);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment