Palindrome Numbers(LA2889)第n个回文数是?

J - Palindrome Numbers

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

 
 
 
WA了一版面,我也是醉了,就因为一个编译环境不同。。。。。。
 
说多了都是泪。
 
 
题目链接:请点击UVALive 2889
 
转载请注明出处:寻找&星空の孩子
 
 
 
 1 #include<stdio.h>
 2 #define LL long long
 3 #define MM 2000000000
 4 LL num[25]= {0};
 5 LL ppow(LL x,LL y)
 6 {
 7     LL tp=1;
 8     while(y--)
 9     {
10         tp*=x;
11     }
12     return tp;
13 }
14 
15 void init()
16 {
17     LL tp=9,i;
18     for(i=1;;)
19     {
20         num[i]=num[i-1]+tp;
21         i++;//同行有多个i要处理的时候i,不要把i++放里面,因为变异环境不同;运算顺序不同,可能会wa
22         num[i]=num[i-1]+tp;
23         i++;
24         tp=tp*10;
25         if(num[i-1]>=MM)break;
26     }
27 
28     /* for(int i=1;i<21;i++)
29     {
30         LL p=(i+1)/2-1;
31         num[i]=num[i-1]+9*ppow(10,p);
32     //        printf("%lld\n",num[i]);
33     }
34     //    printf("%lld\n",num[0]);*/
35 }
36 
37 int main()
38 {
39     init();
40     LL n;
41     LL a[20];
42     while(scanf("%lld",&n),n)
43     {
44         int len=0;
45         for(int i=1; i<=20; i++)
46         {
47             if(n<=num[i])
48             {
49                 len=i;
50                 break;
51             }
52         }
53         //      printf("len=%d\n",len);
54         LL m=n-num[len-1];
55         int l=(len+1)/2;
56 //       printf("m=%lld\tl=%d\n",m,l);
57         LL ans=ppow(10,l-1)+m-1;
58 //       printf("ans=%lld\tppow=%lld\n",ans,ppow(10,l-1));
59         printf("%lld",ans);
60         if(len&1) ans/=10;
61         while(ans)
62         {
63             printf("%lld",ans%10);
64             ans/=10;
65         }
66         printf("\n");
67     }
68     return 0;
69 }

 

 
posted @ 2015-06-10 13:46  寻找&星空の孩子  阅读(915)  评论(0编辑  收藏  举报