Title Description
If a number (the first not 0) from left to right read from right to left is the same, this number is called palindrome number, for example, 12521 is a palindrome number.
Given a positive integer, the number on each digit of it is arranged upside down to form a new number, and then add to the original number, if it is a palindrome stop, if not, then repeat the operation until and to the palindrome number. The given number itself is not a palindrome number.
For example: 87 are:
step1:87+78=165
step2:165+561=726
step3:726+627=1353
step4:1353+3531=4884
Write a program, input M (12<=m<=100), the output at least a few steps to get a palindrome number. If the palindrome number cannot be obtained within 8 steps (including 8 steps), the output is 0.
Input
Line 1th A positive integer l, which represents the number of groups of test data.
Next L line an integer m (12<=m<=100) per line, m itself is not a palindrome number;
Output
Output L line, line I for the input data of line i+1, output the minimum number of steps required, if the number of steps is greater than 8, then output 0.
Sample input
3128789
Sample output
140 Code
#include <stdio.h>
#include <string.h>
int reverse (int x)
{
int num=0;
while (x)
{
num=x%10+num*10;
x/=10;
}
return num;
}
int judge (int x)
{
if (X-reverse (x) ==0)
return 1;
Else
return 0;
}
int main ()
{
int l,m,cnt=0;
scanf ("%d", &l);
while (l--)
{
cnt=0;
scanf ("%d", &m);
while (cnt<=8)
{
if (!judge (m))
{
M=m+reverse (m);
cnt++;
}
Else
{
printf ("%d\n", CNT);
Break
}
}
if (cnt>8)
{
printf ("0\n");
}
}
return 0;
}
Palindrome number C language