Classical judging whether it is a palindrome algorithm

Idea: The palindrome number is the same as the original number after inversion, for example, 1221 is still 1221 after inversion, that is, 1221 is the palindrome number

C++ code

bool Symmetry (long n)
{
	long i,temp;
	i=n; temp=0;
	while(i) //There is no need for length problems, and the numbers are swapped according to the high and low bits
	{
		temp=temp*10+i%10; //i%10 find the number at the end of i
		//The initial temp is 0. The first temp calculates the end number of i
		//For example, the number is 11001. After the calculation, temp is 1. In the next loop, temp is the original last number * 10 + the second-to-last number. Repeatedly, temp is the reversed number of n.
		i/=10;//The number after removing the last number, for example, the number is 11001, after removing i is 1100   
	}
	return(temp==n);//The inverted number is equal to the original number, which is the palindrome number
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325772917&siteId=291194637