zoukankan      html  css  js  c++  java
  • LeetCode

    9. Palindrome Number 

    Problem's Link

     ----------------------------------------------------------------------------

    Mean: 

    给你一个数,判断这个数是不是回文数.

    analyse:

    水题.

    Time complexity: O(N)

     

    view code

    /**
    * -----------------------------------------------------------------
    * Copyright (c) 2016 crazyacking.All rights reserved.
    * -----------------------------------------------------------------
    *       Author: crazyacking
    *       Date  : 2016-02-15-16.34
    */
    #include <queue>
    #include <cstdio>
    #include <set>
    #include <string>
    #include <stack>
    #include <cmath>
    #include <climits>
    #include <map>
    #include <cstdlib>
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    typedef long long(LL);
    typedef unsigned long long(ULL);
    const double eps(1e-8);

    class Solution
    {
    public:
       bool isPalindrome(int x)
       {
           if(x<0) return 0;
           char s[20];
           int cnt=0;
           while(x)
           {
               int tmp=x%10;
               x/=10;
               s[cnt++]=tmp+'0';
           }
           s[cnt]='';
           int len=strlen(s);
           int midLen=len/2;
           int endPos=len-1;
           for(int i=0;i<midLen;++i,--endPos)
           {
               if(s[i]!=s[endPos])
                   return 0;
           }
           return 1;
       }
    };

    int main()
    {
       Solution solution;
       int n;
       while(cin>>n)
       {
           if(solution.isPalindrome(n))
               puts("Yes.");
           else puts("No.");

       }
       return 0;
    }
  • 相关阅读:
    android canvas drawtext 字高
    ios修改UIIMage大小
    聊聊视频播放那些事2
    聊聊视频播放那些事1
    重入锁 ReentrantLock (转)(学习记录)
    setHasFixedSize(true)的意义 (转)
    ActivityLifecycleCallbacks
    NSSet
    阿里云ECS服务器IIS和WampServer同时运行
    ASP.NET MVC4网站部署在阿里ECS云服务器(WIndows Server 2012+IIS8环境)
  • 原文地址:https://www.cnblogs.com/crazyacking/p/5035615.html
Copyright © 2011-2022 走看看