Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

# 20231212 doozuu (이주희) 문제 풀이 업로드 #136

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Doozuu/231212/pro_성격유형검사.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function solution(survey, choices) {
const map = new Map();
const types = ['RT', 'CF', 'JM', 'AN'].map((t) => t.split(''));

function SetScore(t1, t2, score) {
map.set(t1, (map.get(t1) || 0) + Math.abs(score - 4));
Doozuu marked this conversation as resolved.
Show resolved Hide resolved
map.set(t2, map.get(t2) || 0);
}

survey.forEach(([t1, t2], i) => {
const score = choices[i];
score < 4 ? SetScore(t1, t2, score) : SetScore(t2, t1, score);
});

return types.map(([t1, t2]) => (map.get(t1) < map.get(t2) ? t2 : t1)).join('');
}
28 changes: 28 additions & 0 deletions Doozuu/231212/pro_양과늑대.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function solution(info, edges) {
let answer = 0;
let connectedNode = Array.from({length: info.length}, () => []);

edges.forEach(([from, to]) => connectedNode[from].push(to));

function dfs(currentNode, sheep, wolf, possible) {
let newPossibles = [...possible];
let currentIndex = newPossibles.indexOf(currentNode);

info[currentNode] ? wolf++ : sheep++;

answer = Math.max(answer, sheep);

if (sheep === wolf) return;

newPossibles.push(...connectedNode[currentNode]);
newPossibles.splice(currentIndex, 1);

for (const nextNode of newPossibles) {
dfs(nextNode, sheep, wolf, newPossibles);
}
}

dfs(0, 0, 0, [0]);

return answer;
Doozuu marked this conversation as resolved.
Show resolved Hide resolved
}
32 changes: 32 additions & 0 deletions Doozuu/231212/pro_이모티콘할인행사.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function solution(users, emoticons) {
const discountRate = [10, 20, 30, 40];
const rates = [];
let result = [0, 0];

function DFS(depth, arr) {
if (depth === emoticons.length) return rates.push(arr);
for (let i = 0; i < discountRate.length; i++) {
DFS(depth + 1, arr.concat(discountRate[i]));
}
}
DFS(0, []);

for (const rate of rates) {
let [subscribers, sumPrice] = [0, 0];

for (const user of users) {
const [userRate, price] = user;
const ratedPrices = emoticons.reduce((acc, cur, idx) => {
if (rate[idx] >= userRate) return acc + cur * (1 - rate[idx] * 0.01);
return acc;
}, 0);

if (ratedPrices >= price) subscribers++;
else sumPrice += ratedPrices;
}

if (subscribers > result[0] || (subscribers === result[0] && sumPrice >= result[1])) result = [subscribers, sumPrice];
}

return result;
}
29 changes: 29 additions & 0 deletions Doozuu/231212/pro_파일명정렬.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function solution(files) {
function isNumber(n) {
return n !== ' ' && !Number.isNaN(Number(n));
}

function Seperate(name) {
let [head, number] = ['', ''];
for (let i = 0; i < name.length; i++) {
if (isNumber(name[i])) {
number += name[i];
if (!isNumber(name[i + 1])) break;
} else {
head += name[i];
}
}
return [head, Number(number)];
}

return files.sort((a, b) => {
const [head1, number1] = Seperate(a);
const [head2, number2] = Seperate(b);

if (head1.toUpperCase() === head2.toUpperCase()) {
if (number1 === number2) return;
return number1 - number2;
}
return head1.localeCompare(head2);
Doozuu marked this conversation as resolved.
Show resolved Hide resolved
});
}