UVa 748 - Exponentiation

Contents

  1. 1. Problem
  2. 2. Solution
  3. 3. Code

Problem

中文網址

Solution

練習 Java 中…

Code

UVa 748
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

import java.util.Scanner;
import java.math.BigDecimal;

public class Main
{

public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);

while (cin.hasNext())
{
BigDecimal num = cin.nextBigDecimal();
int n = cin.nextInt();
num = num.pow(n);

String s = num.toPlainString();
if (s.charAt(0) == '0')
s = s.substring(1);

int end = s.length();
while (s.charAt(end - 1) == '0')
end--;
if (s.charAt(end - 1) == '.')
end--;
s = s.substring(0, end);
System.out.println(s);
}
}
}