Skip to content

Commit 61fb053

Browse files
authored
[unn04012] 25.01.16 (#29)
* 배열 자르기, 기초 * 배열 회전시키기, 기초 * 제일 작은 수 제거하기, 중급 * 나누어 떨어지는 숫자 배열, 중급 * 행렬의 곱셈, 심화 * 문자열 뒤집기(기초) * 컨트롤_제트(기초) * 영어가_싫어요(기초) * 문자열_계산하기(기초) * 크레인 인형뽑기 게임(중급) * 순서쌍의 갯수(기초) * 점위 위치 구하기(기초) * 카드뭉치(중급) * 햄버거만들기(중급) * 프로세스(심화)
1 parent 22c3f15 commit 61fb053

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

unn04012/queue/Number_of_pairs.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function solution(n) {
2+
const divisors = [];
3+
4+
for (let i = 1; i <= n; i++) if (n % i === 0) divisors.push(i);
5+
return divisors.length;
6+
}
7+
8+
console.log(solution(100));

unn04012/queue/card.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function solution(cards1, cards2, goal) {
2+
const reversedCard1 = cards1.reverse();
3+
const reversedCard2 = cards2.reverse();
4+
5+
for (const word of goal) {
6+
let flag = false;
7+
if (reversedCard1[reversedCard1.length - 1] === word) {
8+
reversedCard1.pop();
9+
flag = true;
10+
} else if (reversedCard2[reversedCard2.length - 1] === word) {
11+
reversedCard2.pop();
12+
flag = true;
13+
}
14+
if (!flag) return 'No';
15+
}
16+
17+
return 'Yes';
18+
}
19+
20+
console.log(solution(['i', 'drink', 'water'], ['want', 'to'], ['i', 'want', 'to', 'drink', 'water']));
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function solution(dot) {
2+
let answer = 0;
3+
const [x, y] = dot;
4+
5+
const quadrant = [
6+
[1, 1],
7+
[-1, 1],
8+
[-1, -1],
9+
[1, -1],
10+
];
11+
12+
for (let i = 0; i < quadrant.length; i++) {
13+
const [x, y] = quadrant[i];
14+
15+
const newX = x * dot[0];
16+
const newY = y * dot[1];
17+
18+
if (newX > 0 && newY > 0) {
19+
answer = i + 1;
20+
break;
21+
}
22+
}
23+
24+
return answer;
25+
}
26+
27+
console.log(solution([-7, 9]));

unn04012/queue/hambuger.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function solution(ingredients) {
2+
let answer = 0;
3+
const queue = [];
4+
5+
for (const ingredient of ingredients) {
6+
queue.push(ingredient);
7+
if (queue.length >= 4) {
8+
const hamburger = queue.slice(-4).join('');
9+
10+
if (hamburger === '1231') {
11+
answer++;
12+
for (let i = 0; i < 4; i++) queue.pop();
13+
}
14+
}
15+
}
16+
17+
return answer;
18+
}
19+
20+
console.log(solution([2, 1, 1, 2, 3, 1, 2, 3, 1]));

unn04012/queue/process.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function solution(priorities, location) {
2+
let answer = 1;
3+
const queue = [];
4+
5+
const prioritiesWithIndex = priorities.map((priority, index) => ({ priority, index }));
6+
7+
while (prioritiesWithIndex.length) {
8+
const { priority, index } = prioritiesWithIndex.shift();
9+
10+
const checkPriority = prioritiesWithIndex.findIndex((e) => e.priority > priority);
11+
12+
// 우선순위가 더 큰 프로세스가 없으면
13+
if (checkPriority === -1) {
14+
if (location === index) return queue.length + 1;
15+
queue.push(priority);
16+
continue;
17+
}
18+
19+
prioritiesWithIndex.push({ priority, index });
20+
}
21+
22+
return answer;
23+
}
24+
console.log(solution([1, 1, 9, 1, 1, 1], 0));

0 commit comments

Comments
 (0)