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);
}
}
}
Poj1001
最新推荐文章于 2019-12-01 23:05:10 发布