Home > Back-end >  Palindrome trap
Palindrome trap

Time:11-08

In digital ocean, there is a special kind of Numbers, called a palindrome, the decision rule is to a number of digital reverse arrangement on whether the natural number is the same with the original, 12321, for example, is a palindrome,
Palindrome like a trap, because a lot of integer repeated calculation according to certain rules, there is always a palindrome, computation rules are as follows:
Suppose there is an integer a, will it your digital reversal after another integer b, and calculate a=a + b, until is a palindrome,
The integer 195, for example,
195 + 591=786
786 + 687=1473
1473 + 3741=5214
5214 + 4125=9339
The end result is a palindrome, 9339

Give any one, please work out how much time required to pass through reverse combined to get a palindrome, and output calculation times and palindrome,
If the input integer is a palindrome, output HW
If the input is not a palindrome, then output the integer into a palindrome experience calculation times and eventually palindrome, two results separated by whitespace
If still did not get when the number of repeated calculation is more than 10 palindrome, output NONE
Enter
Enter an integer value within the scope of the type int,
O
If the input integer is a palindrome, output HW
If the input is not a palindrome, then output the integer into a palindrome experience calculation times and eventually palindrome, two integers separated by whitespace
If you do not get the number of repeated calculation is more than 10 palindrome, output NONE
The sample input Copy
195
Sample output Copy
4 9339
Tip
Intermediate and final results may overflow
# include
# include
Int back (int n);
Int main (void)
{
int i;
Long long int n, b;
The scanf (" % LLD, & amp; n);
If (n==back (n))
Printf (" HW \ n ");
The else
{
for(i=1; i<=10; I++)
{

B=back (n);
N=n + b;
If (n==back (n))
{
Printf (" % d % LLD \ n ", I, n);
break;
}
}
If (i> 10)
Printf (" NONE \ n ");
}
return 0;
}
Int back (int n)
{
Long long int len, I, d, s=0;
Len=log10 (n) + 1;
for(i=1; i<=len; I++)
{
D=n % 10;
S=s * 10 + d;
N=n/10;
}
return s;
}
Validation showed that the wrong answer how to solve, hope to provide advice

CodePudding user response:

Hope you good friend, help me, always verify when submitted for the wrong answer, don't know why,
  • Related