Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
Tags
- js ์ค์ฝํ
- ์ต์ ๋์ฒด์ด๋
- app router emotion
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- suspense ๋ณ๋ชฉํ์
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- suspense ๋์์๋ฆฌ
- ๋ฐฑ์ค 1339๋ฒ js
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- ๋ฐฑ์ค 1339๋ฒ nodejs
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- emotion RSC
- js ๋ฌธ์์ด ์์ถ
- ์ค์ฝํ
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- suspense ๋น๋๊ธฐ
- emtion app router
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- next13 emotion
- ๊ตฌ๋ฆํค
- ์นด์นด์ค ์ฝํ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- suspense react-query
- ๋ฐฑ์ค 2108 nodejs
- js
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- ์ฌ์ฉ์ฑ ๊ฐ์
Archives
- Today
- Total
Lennon FE
[๋ฐฑ์ค 14888๋ฒ] ์ฐ์ฐ์ ๋ผ์๋ฃ๊ธฐ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) ๋ณธ๋ฌธ
๐ฅ Algorithm/Baekjoon
[๋ฐฑ์ค 14888๋ฒ] ์ฐ์ฐ์ ๋ผ์๋ฃ๊ธฐ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs)
Lennon 2022. 2. 18. 20:19728x90
๋ฐ์ํ
https://www.acmicpc.net/problem/14888
const fs = require('fs');
let [n, ...input] = fs.readFileSync('dev/stdin').toString().trim().split('\n');
const [expression, sign] = input.map((v) => v.split(' ').map(Number));
const type = ['+', '-', '*', '/'];
const solution = () => {
const signType = [];
sign.forEach((ele, idx) => {
if (ele !== 0) {
for (let i = 0; i < ele; i++) {
signType.push(type[idx]);
}
}
});
let max = Number.MIN_SAFE_INTEGER;
let min = Number.MAX_SAFE_INTEGER;
for (let ele of permutations(signType)) {
const value = calculate(expression, ele);
max = Math.max(max, value);
min = Math.min(min, value);
}
if (max == '-0' || max == '+0') max = 0;
if (min == '-0' || min == '+0') min = 0;
console.log(`${max}\n${min}`);
function* permutations(elements) {
if (elements.length === 1) {
yield elements;
} else {
const [first, ...rest] = elements;
for (const a of permutations(rest)) {
for (let i = 0; i < elements.length; i++) {
const start = a.slice(0, i);
const ended = a.slice(i);
yield [...start, first, ...ended];
}
}
}
}
function calculate(number, operate) {
let idx = 0;
let finalValue = number[0];
for (let i = 1; i < number.length; i++) {
const value = number[i];
const oper = operate[idx++];
if (oper === '+') {
finalValue += value;
} else if (oper === '-') {
finalValue -= value;
} else if (oper === '*') {
finalValue *= value;
} else {
finalValue = parseInt(finalValue / value);
}
}
return finalValue;
}
};
solution();
์ฃผ์ํ ์
์๋ฐ์คํฌ๋ฆฝํธ๋ +0, -0์ ํ์ํ๋ฏ๋ก ์ฒ๋ฆฌ๊ฐ ํ์ํ๋ค.
๋๋์ ์ ์ ์๋ก ๋์ค๊ฒ ์ฒ๋ฆฌํด์ผํ๋ค.(๋ฌธ์ ์ ์จ์์)
evalํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋น์ฐํ ์๋๋ค.
๋ถํธ์ ๋ํด ์์ด์ ๊ตฌํ ํ ๊ณ์ฐํ๋ฉด ๋์ด๋ค.
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค 2579๋ฒ] ๊ณ๋จ์ค๋ฅด๊ธฐ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.03.11 |
---|---|
[๋ฐฑ์ค 1744๋ฒ] ์ ๋ฌถ๊ธฐ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.18 |
[๋ฐฑ์ค 17140๋ฒ] ์ด์ฐจ์ ๋ฐฐ์ด๊ณผ ์ฐ์ฐ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.17 |
[๋ฐฑ์ค 1541๋ฒ] ์์ด๋ฒ๋ฆฐ ๊ดํธ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.15 |
[๋ฐฑ์ค 1966๋ฒ] ํ๋ฆฐํฐ ํ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.02.15 |
Comments