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
题目来源
||||||:开始用C++写的一直过不了,后来队友提醒X的长度可达100,用long long(不到20位)也存不开,于是用java翻译了一遍,AC#include<iostream>
#include<queue>
#include<string.h>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;
bool judge(int a)
{
int t=a%10;
while(a){
if(t!=a%10)
return false;
a/=10;
}
return true;
}
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
int x,t,z;
while(cin>>x){
t=x;
int y=0;
while(x){
y=y*10+x%10;
x/=10;
}
z=(t-y)/9;
if(z<0)
z=-z;
//cout<<x<<"**"<<y<<"z="<<z<<endl;
if(judge(z))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
BigInteger x,t,y,z;
while(sc.hasNext()){
x=sc.nextBigInteger();
t=x;
y=BigInteger.ZERO;
while(!t.equals(BigInteger.ZERO)){
y=y.multiply(BigInteger.valueOf(10)).add(t.mod(BigInteger.valueOf(10)));
t=t.divide(BigInteger.valueOf(10));
}
z=(x.subtract(y)).divide(BigInteger.valueOf(9));
t=z.mod(BigInteger.valueOf(10)) ;
int flag=1;
while(!z.equals(BigInteger.ZERO)){
if(!(t.equals(z.mod(BigInteger.valueOf(10))))){
flag=0;
break;
}
z=z.divide(BigInteger.valueOf(10));
}
if(flag==1)
System.out.println("YES");
else
System.out.println("NO");
}
}
}