-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const fs = require("fs"); | ||
|
||
const input = fs.readFileSync("/dev/stdin").toString().trim().split("\n"); | ||
|
||
for (let s of input) { | ||
if (s === ".") { | ||
break; | ||
} | ||
|
||
let stack = []; | ||
let check = true; | ||
|
||
for (let i = 0; i < s.length; i++) { | ||
if (s[i] === "(" || s[i] === "[") { | ||
stack.push(s[i]); | ||
} else if (s[i] === ")") { | ||
if (stack.length && stack[stack.length - 1] === "(") { | ||
stack.pop(); | ||
} else { | ||
check = false; | ||
break; | ||
} | ||
} else if (s[i] === "]") { | ||
if (stack.length && stack[stack.length - 1] === "[") { | ||
stack.pop(); | ||
} else { | ||
check = false; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (check && stack.length === 0) { | ||
console.log("yes"); | ||
} else { | ||
console.log("no"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function solution(bookTime) { | ||
const time = Array(60 * 24).fill(0); | ||
|
||
for (const [s, e] of bookTime) { | ||
const start = 60 * parseInt(s.slice(0, 2)) + parseInt(s.slice(3)); | ||
let end = 60 * parseInt(e.slice(0, 2)) + parseInt(e.slice(3)) + 10; | ||
|
||
if (end > 60 * 24 - 1) { | ||
end = 60 * 24 - 1; | ||
} | ||
|
||
for (let i = start; i < end; i++) { | ||
time[i] += 1; | ||
} | ||
} | ||
|
||
return Math.max(...time); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
function isPrime(N) { | ||
if (N === 1) { | ||
return false; | ||
} | ||
for (let i = 2; i <= Math.sqrt(N); i++) { | ||
if (N % i === 0) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
function convert(n, q) { | ||
let revBase = ""; | ||
|
||
while (n > 0) { | ||
const [div, mod] = [Math.floor(n / q), n % q]; | ||
n = div; | ||
revBase += mod.toString(); | ||
} | ||
|
||
return revBase.split("").reverse().join(""); | ||
} | ||
|
||
function solution(n, k) { | ||
let answer = 0; | ||
for (const i of convert(n, k).split("0")) { | ||
if (i !== "") { | ||
if (isPrime(parseInt(i))) { | ||
answer += 1; | ||
} | ||
} | ||
} | ||
return answer; | ||
} |