Description:
There is a positive integer X, X's reversion count is Y. For example, X=123, Y=321; X=1234, Y=4321. Z=(X-Y)/9, Judge if Z is made up of only one number(0,1,2...9), like Z=11,Z=111,Z=222,don't consider '+'and '-'.
Input:
Input contains of several test cases. Each test case only contains of a number X, L is the length of X. ( 2 <= L < 100)
Output:
Output “YES”or “NO”.
样例输入
10 13
样例输出
YES
YES
找规律一直WA,就用JAVA大数暴力了一发,果然过了。
import java.math.BigInteger;
import java.util.Scanner;
import java.io.*;
public class Main
{
public static void main(String args[])
{
Scanner cin = new Scanner(System.in);
while(cin.hasNext())
{
BigInteger x,y,z,xx;
x=cin.nextBigInteger();
xx=x;
y=BigInteger.ZERO;
z=BigInteger.ZERO;
BigInteger n,k;
n=BigInteger.ZERO;
k=BigInteger.ZERO;
while(x.compareTo(BigInteger.valueOf(0))!=0)
{
n=x.mod(BigInteger.valueOf(10));
y=y.multiply(BigInteger.valueOf(10));
y=y.add(n);
x=x.divide(BigInteger.valueOf(10));
}
z=xx.subtract(y);
z=z.abs();
z=z.divide(BigInteger.valueOf(9));
n=z.mod(BigInteger.valueOf(10));
z=z.divide(BigInteger.valueOf(10));
k=n;
// System.out.println(n);
// System.out.println(k);
int f=1;
while(z.compareTo(BigInteger.valueOf(0))!=0)
{
n=z.mod(BigInteger.valueOf(10));
if(k.compareTo(n)!=0)
{
f=0;
break;
}
z=z.divide(BigInteger.valueOf(10));
}
if(f==1)System.out.println("YES");
else System.out.println("NO");
}
}
}