ZOJ 1078 枚举法

View Code
 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<string.h>
 4 #include<math.h>
 5 
 6 
 7 int main()
 8 {
 9     int i, t, j, m, ncases;
10     int num, k, flag,a[18];
11     
12     while(scanf("%d",&num) != EOF)
13     {
14        if(num == 0) break;
15        flag = 0;
16        for(i=2; i<=16; i++)
17        {
18            a[i] = 0;
19            t = num;
20            m = 0; 
21            while( t )
22            {
23               m = m*i + t%i;
24               t /= i;
25            } 
26            if(m== num)
27            {
28              a[i] = 1;
29              flag = 1;
30            }
31        }   
32     if( flag )
33     {
34        printf("Number %d is palindrom in basis",num);
35        for(i = 2; i <= 16; i++)
36        {  
37             if(a[i] == 1) 
38               printf(" %d",i);
39        } 
40        printf("\n");
41     }   
42     else
43     {
44         printf("Number %d is not a palindrom\n",num);         
45     } 
46    }
47     
48    return 0;
49 }   
posted @ 2012-08-28 23:05  zhongya  阅读(219)  评论(0编辑  收藏  举报