palindrome number

就是判断一个数是不是回文数字。

 

 1 #include <iostream>
 2 using namespace std;
 3 bool bIsPalindrome(int x)
 4 {
 5     if(x<0)
 6     {
 7         return false;
 8     }
 9     if(x==0)
10     {
11         return true;
12     }
13     int iBase = 1;
14     while(x/iBase >= 10)
15     {
16         iBase *= 10;
17     }
18     
19     while(x >= 10)
20     {
21         int iLeft = x/iBase;
22         int iRight = x%10;
23         if(iLeft != iRight)
24         {
25             return false;
26         }
27         x = x - iLeft*iBase;
28         x /= 10;
29         iBase /= 100;
30     }
31     //x=100021 , x=1001
32     if((iBase >= 10) && (x != 0))
33     {
34         return false;
35     }
36     return true;
37 }
38 int main()
39 {
40     cout<<bIsPalindrome(100)<<endl;
41     getchar();
42     return 0;
43 }

 

posted @ 2014-12-02 18:39  MDGSF  阅读(122)  评论(0)    收藏  举报