POJ1894 JAVA高精度水

这两天都在找JAVA高精度的题做,主要是想偷懒,而且JAVA确实做ACM很强大,所以就多练练JAVA做题。

A了好几道水题,这道也挺水,结果读题读错了!!唉呀 ,英语是硬伤啊。。。

 

题意:进制转换,但将0的部分去掉用进制数来表示。

思路很简单,看代码就行了。结果因为读错题花了一晚上的代价。。。

import java.math.*;
import java.util.*;
public class Main {
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
	 BigInteger B,x,tmp,one;
	 int p=0;
    Scanner cin = new Scanner(System.in);
    B=cin.nextBigInteger();
    x=cin.nextBigInteger();
    tmp=BigInteger.ONE;
    one=BigInteger.ONE;
    while(x.compareTo(tmp)>=0)
    {
    	x=x.subtract(tmp);
    	tmp=tmp.multiply(B);
    	p++;
    }
    while(p!=0)
    {
    	tmp=tmp.divide(B);
    	System.out.print(x.divide(tmp).add(one));
    	x=x.mod(tmp);
    	p--;
    }
  	System.out.println();
  	System.exit(0);

 }

}


 

posted @ 2013-03-20 22:10  amourjun  阅读(171)  评论(0编辑  收藏  举报