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
import java.util.Scanner;
import java.math.BigInteger;
public class Main{
public static void main(String args[])
{
Scanner scan=new Scanner(System.in);
while(scan.hasNext())
{
String str=scan.next();
String str1=new StringBuilder(str).reverse().toString();//字符串逆序的方法
BigInteger x=new BigInteger(str);
BigInteger y=new BigInteger(str1);
if(x.compareTo(y)<0){//因为对于Z来说,都是正数,所以要用大的数值减去小的。
BigInteger tt=x;
x=y;
y=tt;
}
x=x.subtract(y);
String res=x.divide(BigInteger.valueOf(9)).toString();//相除后再转成字符串
char []ch=res.toCharArray();
int flag=0;
for(int i=1;i<ch.length;i++){
if(ch[0]!=ch[i]){
System.out.println("NO");
flag=1;
break;
}
}
if(flag==0)
System.out.println("YES");
}
}
}