Reversion Count

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");
}
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值