首页 > 其他 > 详细

POJ 1001 Exponentiation(大数处理)

时间:2014-03-14 18:02:18      阅读:451      评论:0      收藏:0      [点我收藏+]

http://poj.org/problem?id=1001

 

题意:给你一个浮点数,一个整数,求浮点数的整数次方。

 

思路:大数解决,注意处理后面多余的零跟前面多余的零,以及Java科学计数法的问题。

 

bubuko.com,布布扣
 1 import java.math.*;
 2 import java.util.Scanner;
 3 
 4 public class Main {    
 5     public static void main(String[] args) {
 6         // TODO Auto-generated method stub
 7         /*sss*/
 8         BigDecimal a, c, d;
 9         int b ;
10         Scanner cin = new Scanner(System.in);
11         while(cin.hasNext()){
12             a = cin.nextBigDecimal();
13             b = cin.nextInt();
14             a = a.pow(b);
15             String s;
16             s = a.toPlainString();  //避免科学记数法(如果用a.toSting会存成科学记数法)
17             int start = 0;
18             while(s.charAt(start) == ‘0‘){   //a.charAt(b) 取a字符串下标为b的字符
19                 start++;
20             }
21             int end = s.length()-1;
22             while(s.charAt(end) == ‘0‘){
23                 end--;
24             }
25             if(s.charAt(end) == ‘.‘){
26                 end--;
27             }
28             for(int i = start; i <= end; ++i){
29                 System.out.print(s.charAt(i));
30             }
31             System.out.println();
32             
33             //System.out.println();//subtract-, add+, multiply* divide/ 
34         }
35         cin.close();
36     }    
37 }
Exponentiation

POJ 1001 Exponentiation(大数处理),布布扣,bubuko.com

POJ 1001 Exponentiation(大数处理)

原文:http://www.cnblogs.com/Silence-AC/p/3599541.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!