uva748 - Exponentiation
3398 ワード
import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class Exponentiation {
public static void main(String[] args){
Scanner sc = new Scanner(new BufferedInputStream(System.in));
BigDecimal bd1, ans;
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(110); //
int n, i;
String st;
while(sc.hasNextLine()){
st = sc.nextLine();
String[] s = st.split(" +");
bd1 = new BigDecimal(s[0]);
n = Integer.parseInt(s[1].trim());
ans = new BigDecimal("1");
for(i = 1; i <= n; ++i){
ans = ans.multiply(bd1);
}
String result = df.format(ans);
String[] str = result.split("\\."); /// '.' "\\."
//System.out.println(str[0]);
if(str[0].equals("0")){ /// equals()
System.out.println("." + str[1]);
}else{
result = result.replace(",",""); /// ',' 。。。
System.out.println(result);
}
//System.out.println(result);
}
sc.close();
}
}
uvaは時々問題を判断して結果をあげないで、私は拭きます...