Java的大数计算BigNumber
Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again!
Now you are suppose to check if there are more numbers with this property. That is, double a given number with k digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.
Input Specification:
Each input file contains one test case. Each case contains one positive integer with no more than 20 digits.
Output Specification:
For each test case, first print in a line "Yes" if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or "No" if not. Then in the next line, print the doubled number.
Sample Input:
1234567899
Sample Output:
Yes
2469135798
不知道为什么有一个样例没过,觉得写得没毛病啊
import java.math.BigInteger;
import java.util.Scanner; public class A { public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
BigInteger a = cin.nextBigInteger();
BigInteger bb = a;
BigInteger c = BigInteger.valueOf(10);
BigInteger d;
BigInteger ans = a.add(bb);
BigInteger b = ans;
boolean book = true;
int[] book0 = new int[10];
while(!a.equals(BigInteger.valueOf(0))) {
// System.out.println(a.equals(0));
d = a.mod(c);
a = a.divide(c);
book0[d.intValue()] = 1;
}
while(!b.equals(BigInteger.ZERO)) {
d = b.mod(c);
b = b.divide(c);
if(book0[d.intValue()] != 1) {
book = false;
break;
}
}
if(book == false) {
System.out.println("No");
}
else {
System.out.println("Yes");
}
System.out.println(ans); } }
Java的大数计算BigNumber的更多相关文章
- Java & C++ 大数计算
Java--大数计算,妈妈再也不用担心我的学习了 . BigInteger 英文API: http://docs.oracle.com/javase/8/docs/api/ 中文API: http:/ ...
- HDU 5686 斐波那契数列、Java求大数
原题:http://acm.hdu.edu.cn/showproblem.php?pid=5686 当我们要求f[n]时,可以考虑为前n-1个1的情况有加了一个1. 此时有两种情况:当不适用第n个1进 ...
- 【Java】Float计算不准确
大家可能都遇到过,float在计算某些值时,会有不准确的情况. 比如如下情况: > 计算不准确 package com.nicchagil.study.java.demo.No10float计算 ...
- Java BigInteger(大数,ACM比赛专用)
用c或者C++处理大数比较麻烦,于是决心学习一下JAVA中大数运算. 先下载一个eclipse,具体的用法去问度娘吧 JAVA中有两个类BigInteger和BigDecimal分别表示大整数类和大浮 ...
- Java的大数操作分为BigInteger和BigDecimal
Java的大数操作分为BigInteger和BigDecimal,但这两给类是分开使用的,有时候在编程的时候显得略微繁琐,现在编写了一个将二者合二为一的大数操作类. 大数操作类代码如下: 1 pack ...
- JAVA解决大数
主题链接:CLICK HERE~ 有了Java求解大数变得如此简单,以后再也不用操心大数模板了.哦啦啦啦. import java.math.BigInteger; import java.math. ...
- 用Java进行大数处理(BigInteger)-hdu1042
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 题目描述: 代码实现: import java.util.Scanner; import jav ...
- Java闰年的计算,Calendar的用法
Java闰年的计算,Calendar的用法 代码如下: package com.aaa.zuoye; import java.text.ParseException; import java.util ...
- Java基础-时间复杂度计算方式
Java基础-时间复杂度计算方式 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 时间复杂度通常是衡量算法的优劣的,衡量算法的时间严格来讲是很难衡量的,由于不同的机器性能不用环境 ...
随机推荐
- 用yii2给app写接口(上)
Yii2如何实现RESTful风格的API 1.建立单独的应用程序 为了增加程序的可维护性,易操作性,我们选择新建一套应用程序,这也是为了和前台应用.后台应用区分开操作.有些人要嚷嚷了,为啥非得单独搞 ...
- 在windows上安装nginx
在windows上安装nginx 最近自己也尝试了一下在windows上安装nginx,其实非常的简单,这里算是备忘一下. 首先需要到nginx的官网上下载最新版的nginx:http://n ...
- Win10 部署 依赖 NET3.5 项目,报错 无法安装 NET3.5 ,该如何解决?
下载 NetFx3.cab Cab 安装包 拷贝 NetFx3.cab 文件至 C:\Windows 目录 打开命令行窗口(管理员权限) 输入以下内容: dism /online /Enable-Fe ...
- POJ - 1182 食物链 并查集经典
思路:设r(x)表示节点x与根结点的关系,px表示x的根结点.记录每个节点与其父节点的关系,就能很方便知道每个节点以及和它的父节点的关系. struct node{ int par; //父亲节点 i ...
- php留言板
这个小项目的学习,就这样结束啦.由于过程中需要使用到js,这个目前还是感觉不会.之前的分析还是不太懂的.现在心里还是有点迷茫.什么都是照着葫芦画瓢. 我的拥有自己的东西才行.
- mac 系统安装 eclipse 方法
经过好几天的折腾,终于在各种不靠谱的经验.说明的忽悠中把自己心爱的 mac 安装上了 eclipse,看到别人的不靠谱,我决定自己写一篇经验,为了大家能够不走我这么多的弯路,也为了自己将来可以回来看看 ...
- zTree实现获取一级节点数据
zTree实现获取一级节点数据 1.实现源码 <!DOCTYPE html> <html> <head> <title>zTree实现基本树</t ...
- VxWorks6.6 pcPentium BSP 使用说明(三):设备驱动
本文主要介绍了pcPentium BSP中包含的驱动程序.包含了官方提供的所有驱动程序,除了aic7888Lib--现在已用得很少的一个AIC-7888 SCSI控制器的驱动介绍.建议重点阅读at ...
- pat1111-1120
1111 比较麻烦的最短路 #include<cmath> #include<map> #include<iostream> #include<cstring ...
- 玲珑杯#2.5 A-B
这个题解错了网上还没有题解 囧 = (i%2)? 1 : -1 = - * * *= m #include<bits/stdc++.h> using namespace std; type ...