Poj1001

package easy;


import java.io.BufferedInputStream;
import java.math.BigDecimal;
import java.util.Scanner;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*终于过了,之前一直是re,搞不懂为什么?
* 可能是在处理格式方面有问题吧,因为之前是用format。
* 之前不知道BigDecimal里有几个很好用的方法,后来上网看了下,才知道,有这几个方法。
* 唉,看API时,太不仔细了。
* Poj1001
*
* @author NC
*/
public class Poj1001 {

public static void main(String[] args) {
Scanner scanner = new Scanner(new BufferedInputStream(System.in));
while (true) {
String s = scanner.nextLine();
String[] ss = s.trim().split(" ");
BigDecimal bd = new BigDecimal(ss[0]);
int n;
int i=1;
while(ss[i].equals("")){//如果中间多几个空格,会有空字符串,这里去空字符串
i++;
}
n = Integer.parseInt(ss[i]);
bd = bd.pow(n);
bd = bd.stripTrailingZeros();//去掉尾部的0
String result = bd.toPlainString();//转字符串(无指数形式的)
if (result.startsWith("0.")) {//要0.才行,0的话会wrong answer
result = result.substring(1);//去掉前面的0
}
System.out.println(result);
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值