Skip to content

Commit

Permalink
5.23: regex(한국이 그리울 땐 서버에 접속하지, 가장 긴 단어)
Browse files Browse the repository at this point in the history
  • Loading branch information
luckylooky2 committed May 23, 2024
1 parent 3fb95b3 commit 2010267
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
15 changes: 15 additions & 0 deletions baekjoon/5637.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 가장 긴 단어 : 정규 표현식
const input = require("fs").readFileSync("/dev/stdin").toString().trim();
const text = input;
const regex = /[A-Za-z-]+/g;
let answer = "";

const candidates = text.match(regex);

for (const word of candidates) {
if (answer.length < word.length) {
answer = word;
}
}

console.log(answer.toLowerCase());
20 changes: 20 additions & 0 deletions baekjoon/9996.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 한국이 그리울 땐 서버에 접속하지 : 정규 표현식
const input = require("fs")
.readFileSync("/dev/stdin")
.toString()
.trim()
.split("\n");
const n = Number(input.shift());
const strings = input;
const [start, end] = input.shift().split("*");
const regex = new RegExp(`^${start}[a-z]*${end}$`);
const answer = [];

for (const string of strings) {
const res = regex.test(string);
answer.push(res ? "DA" : "NE");
}

console.log(answer.join("\n"));

// 17'00"

0 comments on commit 2010267

Please sign in to comment.