题目链接
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
题目来源
2018 ACM-ICPC 中国大学生程序设计竞赛线上赛
解题思路:
用Java大数模板写
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
while(in.hasNextLine()) {
String s = in.nextLine();//不能使用in.next();
BigInteger a,b,t;
a = new BigInteger(s);
b = new BigInteger(new StringBuilder(s).reverse().toString());
t = a.subtract(b).divide(BigInteger.valueOf(9)).abs();
if(jug(t)) System.out.println("YES");
else System.out.println("NO");
}
}
public static boolean jug(BigInteger a) {
String s = a.toString();
for(int i = 1;i < s.length();i++) if(s.charAt(i) != s.charAt(i - 1)) return false;
return true;
}
}