Palindrome Number Problem Solving report

Source: Internet
Author: User

Determine whether an integer is a palindrome. Do this without extra space.

Some hints:

Could negative integers be palindromes? (ie,-1)

If you is thinking of converting the integer to string, note the restriction of using extra space.

You could also try reversing an integer. However, if you had solved the problem "Reverse integer", you know that the reversed integer might overflow. How do would handle such case?

There is a more generic the solving this problem.

So the key to the problem is to remember to judge the negative, the program is very ugly writing.

1 //2 //main.cpp3 //Longest Substring4 //5 //Created by Bowie Hsu on 29/11/21.6 //Copyright (c) 2014 Bowie Hsu. All rights reserved.7 //8 9#include <iostream>Ten#include <string> One#include <sstream> A#include <vector> -#include"stdio.h" -#include"ctype.h" the  - using namespacestd; -  - classSolution + { -  Public: +     BOOLIspalindrome (intx) A     { at         //record the length of an input integer -         if(x<0) { -             return 0; -         } -         intA=1; -         intp=0; in         intCalc=x; -          while(calc/Ten!=0) to         { +a=a*Ten; -calc=calc/Ten; the++p; *         } $         inttest=A;Panax Notoginseng         intBig=x,small=x; -         BOOLbign=1; the         intCha=0; +          while(small) A         { the             if(big/test!=small%Ten) +bign=0; -              $cha=big/test; $big=big-test*cha; -test=test/Ten; -small=small/Ten; the  -         }Wuyi         returnbign; the     } - }; Wu  - intMain () About { $     intinput=1211; -     BOOLans; - solution x; -ans=x.ispalindrome (input); Acout<<ans<<Endl; +    //cout<< "What the fuck?"; the}

Palindrome Number Problem Solving report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.