๐ฅ Algorithm/Baekjoon
[๋ฐฑ์ค 2607๋ฒ] ๋น์ทํ ๋จ์ด - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs)
Lennon
2022. 5. 7. 00:27
728x90
๋ฐ์ํ
https://www.acmicpc.net/problem/2607
const { off } = require('process');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
rl.on('line', function (line) {
input.push(line);
if (input.length === +input[0] + 1) {
rl.close();
}
}).on('close', function () {
input.shift();
const firstStr = input[0];
const validationStr = input.slice(1);
console.log(
solution(
firstStr.split(''),
validationStr.map((v) => v.split(''))
)
);
});
function solution(standard, validation) {
let answer = 0;
validation.forEach((v) => {
const start = [...standard];
if (v.length < start.length) {
for (let i = 0; i < v.length; i++) {
if (start.includes(v[i])) {
const idx = start.indexOf(v[i]);
start.splice(idx, 1);
}
}
if (start.length === 1) {
answer++;
}
} else {
for (let i = 0; i < start.length; i++) {
if (v.includes(start[i])) {
const idx = v.indexOf(start[i]);
v.splice(idx, 1);
}
}
if (v.length === 1 || v.length === 0) {
answer++;
}
}
});
return answer;
}
์ค๋ฒ4 ์ฃผ์ ์ ์ ๋ต๋ฅ ์ด 27ํผ์ธ ๋ฌธ์ ์ด๋ค.
๋ณธ์ธ๋ ๊ณ์ ํ๋ ค์ ์๋ฌธ์ ๊ฐ์ง๊ณ ์ฝ๋๋ฅผ ํ์คํ์ค ํด์ํ๋ค๋ณด๋ ๋ฐ๋ณด๊ฐ์ด ์ฒ๋ฆฌํ ๋ถ๋ถ์ด ์์ด์ ๊ทธ๋ฐ ๊ฑฐ์๋ค.
๋น๊ตํ ๋ฌธ์์ด์ ๊ธธ์ด๋ฅผ ๋ฐ์ ธ ๋ ๊ฐ์ง ๊ฒฝ์ฐ๋ก ํด์ํ๋ฉด ์ฝ๊ฒ ํ ์ ์๋ค.
728x90
๋ฐ์ํ