2014-09-08

748 - Exponentiation


題目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=97&page=show_problem&problem=689


import java.util.*;
import java.lang.*;
import java.math.BigDecimal;

public class Main{
 
 public  static void main(String[] args) {
  
  Scanner keyin = new Scanner(System.in);
  boolean first = true;
  
  
  
  while(keyin.hasNext()){
     
   String base = keyin.next();
   int exp = keyin.nextInt();
   keyin.nextLine();
   
   BigDecimal num = new BigDecimal(base);
   BigDecimal output = num.pow(exp).stripTrailingZeros();
   
   if(output.intValue()==0){
    String zeroResult = (output.toPlainString()).substring(1,(output.toPlainString()).length());
    System.out.println(zeroResult);
    }
   else
   System.out.println(output.toPlainString());
   
  
  }
 }
 
 
 }


沒有留言:

張貼留言

(VM) Ubuntu enable ssh

OS版本:14.04 LTS 相關指令: sudo apt-get install openssh-server Port forwarding設定 : 以virtual box為例子,網路->進階->連接阜轉送(port forwarding) ...