PKU 1001 Exponentiation

PKU 1001 Exponentiation

Run IDUserProblemResultMemoryTimeLanguageCode LengthSubmit Time
5068074kingpro1001Accepted1108K94MSJava1469B2009-04-29 19:18:29
ContractedBlock.gif ExpandedBlockStart.gif PKU 1001 Exponentiation
 1  import  java.io.BufferedReader;
 2  import  java.io.IOException;
 3  import  java.io.InputStreamReader;
 4  import  java.math.BigDecimal;
 5  import  java.util.logging.Level;
 6  import  java.util.logging.Logger;
 7 
 8  public   class  Main {
 9 
10       public   static   void  main(String[] args) {
11           try  {
12              BufferedReader reader  =   new  BufferedReader( new  InputStreamReader(System.in));
13              String data  =   null ;
14               while  ((data  =  reader.readLine())  !=   null ) {
15                  String[] d  =  data.split( " \\s+ " );
16                  BigDecimal r  =   new  BigDecimal(d[ 0 ]);
17                   int  n  =  Integer.parseInt(d[ 1 ]);
18                  BigDecimal result  =  r.pow(n);
19                  String res  =  result.toPlainString();
20                   int  i  =   0 ;
21                   for  (; i  <  res.length(); i ++ )
22                       if  (res.charAt(i)  !=   ' 0 ' )
23                           break ;
24                   int  j = res.length() - 1 ;
25                   for (; j >= i; j -- )
26                       if (res.charAt(j) != ' 0 ' )
27                           break ;
28                   if (res.charAt(j) == ' . ' )
29                      j -- ;
30                  System.out.println(res.substring(i, j + 1 ));
31              }
32          }  catch  (IOException ex) {
33              Logger.getLogger(Main. class .getName()).log(Level.SEVERE,  null , ex);
34          }
35      }
36  }

 

Java BigDecimal类 使用toPlainString()方法获取全部位

转载于:https://www.cnblogs.com/Kingpro/archive/2010/04/06/PKU_1001_Exponentiation.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值