-
Notifications
You must be signed in to change notification settings - Fork 3
/
_748_Exponentiation.java
37 lines (28 loc) · 989 Bytes
/
_748_Exponentiation.java
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
33
34
35
36
37
package io.github.tahanima.uva;
import java.math.BigDecimal;
import java.util.Scanner;
/**
* @author tahanima
*/
public class _748_Exponentiation {
public static String process(StringBuilder number) {
while (number.charAt(0) == '0')
number.deleteCharAt(0);
int size = number.length() - 1;
while (number.charAt(size) == '0')
number.deleteCharAt(size--);
return number.toString();
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
StringBuilder stringBuilder = new StringBuilder();
while (scanner.hasNext()) {
double R = scanner.nextDouble();
int n = scanner.nextInt();
BigDecimal answer = BigDecimal.valueOf(R);
answer = answer.pow(n);
stringBuilder.append(String.format("%s%n", process(new StringBuilder(answer.toPlainString()))));
}
System.out.print(stringBuilder);
}
}