POJ 1001 Exponentiation
来源:互联网 发布:香港大学 专业 知乎 编辑:程序博客网 时间:2024/06/05 16:06
最裸的高精度幂,记录一下Java里面高精度类的用法而已
1 import java.io.*; 2 import java.util.Scanner; 3 import java.math.*; 4 5 public class Main 6 { 7 public static void main(String[] args) 8 { 9 Scanner cin = new Scanner(System.in);10 while(cin.hasNext()) {11 int m;12 String sn;13 sn = cin.next();14 m = cin.nextInt();15 BigDecimal n = new BigDecimal(sn);16 String ans = n.pow(m).toPlainString();17 if(ans.charAt(0) != '0') System.out.print(ans.charAt(0)); 18 int len = ans.length();19 while(ans.charAt(len - 1) == '0') len--;20 if(ans.charAt(len - 1) == '.') len--;21 for(int i = 1;i < len;i++) System.out.print(ans.charAt(i));22 if(len == 1 && ans.charAt(0) == '0') System.out.print('0');23 System.out.print('\n');24 }25 }26 }
其中BigDecimal类的toPlainString方法可以将浮点数转化成精确形式的字符串而不是科学计数法表示
0 0
- POJ 1001 Exponentiation
- POJ 1001 Exponentiation
- poj 1001 Exponentiation
- POJ 1001 "Exponentiation"
- poj 1001 Exponentiation
- POJ 1001 Exponentiation
- poj 1001 exponentiation
- 【POJ】1001 Exponentiation
- POJ 1001 Exponentiation
- poj 1001Exponentiation
- 《POJ 1001》 Exponentiation
- POJ 1001 Exponentiation
- [POJ]1001 Exponentiation
- POJ-1001-Exponentiation
- [poj] 1001 Exponentiation
- POJ 1001 Exponentiation
- poj 1001 Exponentiation
- POJ-1001 Exponentiation 高精度
- Aoj 560 取石子
- AOJ 435 带小数高精度
- AOJ 401 Fibonacci & GCD
- POJ 2049 Finding Nemo
- 6-2对象作为数据成员
- POJ 1001 Exponentiation
- StringBuilder类的使用
- HDU 2492 PingPong
- POJ 3264 Balanced Lineup (RMQ问题)
- Android——扩大ImageButton的点击区域
- NOIP 2006 金明的预算方案(带条件的01背包)
- HDU 2955 Robberies
- HDU 1864 最大报销额
- LA3708 Graveyard 墓地雕塑