티스토리 뷰
https://www.acmicpc.net/problem/9935
9935번: 문자열 폭발
첫째 줄에 문자열이 주어진다. 문자열의 길이는 1보다 크거나 같고, 1,000,000보다 작거나 같다. 둘째 줄에 폭발 문자열이 주어진다. 길이는 1보다 크거나 같고, 36보다 작거나 같다. 두 문자열은 모
www.acmicpc.net
const fs = require('fs');
const input = fs.readFileSync("./dev/stdin").toString().trim().split("\n").map(v => v.trim())
const str = input[0]
const target = input[1];
const r_target = target.split('').reverse();
const last = target[target.length - 1];
const answer = [];
const check = () => {
if (answer.length < target.length - 1) return false
for (let i = 1; i < target.length; i++) {
if (r_target[i] != answer[answer.length - i]) {
return false;
}
}
return true;
}
for (let i = 0; i < str.length; i++) {
const now = str[i];
if (now == last && check()) {
for (let j = 0; j < target.length - 1; j++) {
answer.pop();
}
} else {
answer.push(now);
}
}
if (answer.length == 0) {
console.log('FRULA')
} else {
console.log(answer.join(''))
}
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 14469: 소가 길을 건너간 이유 3 (0) | 2022.04.08 |
---|---|
Node.js)백준 1781번: 컵라면 (0) | 2022.04.08 |
Node.js) 백준 2109번: 순회강연 (0) | 2022.04.08 |
Node.js) 백준 2170번: 선 긋기 (0) | 2022.04.08 |
Node.js) 백준 14729번: 칠무해 (0) | 2022.04.07 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 로드나인
- 은둔청년체험
- 다이나믹프로그래밍
- 면접질문
- 동적프로그래밍
- 개발자면접
- 투포인터
- 서버개발
- create databases;
- MySQL
- 투포인터 연습
- KMP
- BFS
- DB 생성
- 다이나밍프로그래밍
- 롱베케이션
- node.js
- 면접비
- 서버점검
- 최소공통조상
- 그래프
- create db
- MOD
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함