Definition of palindrome number and extension of use

Source: Internet
Author: User

Palindrome number

Definition: The same number as the read-back read, read from left to right and read from right to left is exactly the same natural number. For example: 91,11,202,1001 and so on, 1011 is not.

Topic 1: Enter two number l,r, Output x. where x satisfies the number of palindrome numbers within the [L,r] range.
1#include <iostream>2#include <stdio.h>3#include <math.h>4 5 using namespacestd;6 intHuiwen (intnum)7 {8     into = num;//O Store Positive order9     intTMP =0;Ten      while(num! =0)//tmp Store Reverse order One     { ATMP *=Ten; -TMP + = num%Ten; -Num/=Ten; the     } -     if(TMP = = O)//whether the normal sequence of palindrome number is quite to judge -     //if (tmp%10 = = o%10)//Single -digit judgment in reverse order -     { +         return 1; -     } +     return 0; A } at  - intMain () - { -     intL,r; -scanf"%d%d",&l,&R); -     intCount=0; in      for(inti=l;i<=r;i++) -     { to         if(Huiwen (i) = =1) count++; +     } -cout<<count<<Endl; the     return 0; *}

Expansion: Defines a special palindrome number, which requires only the first and the tail equal. Example: 8,11,202,1001,1011, etc.

Topic 2: Enter two number l,r, Output x. where x satisfies the number of palindrome numbers within the [L,r] range.
1#include <iostream>2#include <stdio.h>3#include <math.h>4 5 using namespacestd;6 intHuiwen (intnum)7 {8     into = num;//O Store Positive order9     intTMP =0;Ten      while(num! =0)//tmp Store Reverse order One     { ATMP *=Ten; -TMP + = num%Ten; -Num/=Ten; the     } -     //if (tmp = = O)//whether the normal sequence of palindrome number is quite to judge -     if(tmp%Ten= = o%Ten)//Single -digit judgment in reverse order -     { +         return 1; -     } +     return 0; A } at  - intMain () - { -     intL,r; -scanf"%d%d",&l,&R); -     intCount=0; in      for(inti=l;i<=r;i++) -     { to         if(Huiwen (i) = =1) count++; +     } -cout<<count<<Endl; the     return 0; *}

Definition of palindrome number and extension of use

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.