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