forked from xeoneux/30-Days-of-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.js
49 lines (42 loc) Β· 1.04 KB
/
Solution.js
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
38
39
40
41
42
43
44
45
46
47
48
49
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
//Write your code here
class Calculator {
constructor() {
this.power = function (n, p) {
if (n < 0 || p < 0) {
return ('n and p should be non-negative')
} else {
return n ** p
}
}
}
}
function main() {
var myCalculator = new Calculator();
var T = parseInt(readLine());
while (T-- > 0) {
var num = (readLine().split(" "));
try {
var n = parseInt(num[0]);
var p = parseInt(num[1]);
var ans = myCalculator.power(n, p);
console.log(ans);
} catch (e) {
console.log(e);
}
}
}