-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
5.23: regex(한국이 그리울 땐 서버에 접속하지, 가장 긴 단어)
- Loading branch information
1 parent
3fb95b3
commit 2010267
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |