-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path!28086_parubitto-chan.js
63 lines (58 loc) · 1.59 KB
/
!28086_parubitto-chan.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// 28086 미소녀 컴퓨터 파루빗토 쨩
let fs = require("fs");
let input = fs.readFileSync("input.txt").toString().trim();
if (input.includes("+")) {
let [a, b] = input.split("+");
const [demicalA, demicalB] = octalToDemical(a, b);
const result = demicalToOctal(demicalA + demicalB);
if (result) {
console.log(result);
} else {
console.log("invalid");
}
} else if (input.includes("/")) {
let [a, b] = input.split("/");
const [demicalA, demicalB] = octalToDemical(a, b);
const result = demicalToOctal(Math.floor(demicalA / demicalB));
if (result) {
console.log(result);
} else {
console.log("invalid");
}
} else if (input.includes("*")) {
let [a, b] = input.split("*");
const [demicalA, demicalB] = octalToDemical(a, b);
const result = demicalToOctal(demicalA * demicalB);
if (result) {
console.log(result);
} else {
console.log("invalid");
}
} else if (input.includes("-")) {
let spl = input.split("-");
console.log(spl);
if (spl.length === 2) {
const [demicalA, demicalB] = octalToDemical(spl[0], spl[1]);
const result = demicalToOctal(demicalA - demicalB);
if (result) {
console.log(result);
} else {
console.log("invalid");
}
} else {
const [demicalA, demicalB] = octalToDemical(-spl[1], spl[2]);
const result = demicalToOctal(demicalA - demicalB);
if (result) {
console.log(result);
} else {
console.log("invalid");
}
}
}
function octalToDemical(...rest) {
let temp = rest.map((x) => parseInt(x, 8));
return temp;
}
function demicalToOctal(num) {
return num.toString(8);
}