(大数)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
题目来源

2018 ACM-ICPC 中国大学生程序设计竞赛线上赛

||||||:开始用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");
			
			
		}
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值