티스토리 뷰
https://www.acmicpc.net/problem/2529
2529번: 부등호
두 종류의 부등호 기호 ‘<’와 ‘>’가 k개 나열된 순서열 A가 있다. 우리는 이 부등호 기호 앞뒤에 서로 다른 한 자릿수 숫자를 넣어서 모든 부등호 관계를 만족시키려고 한다. 예를 들어, 제시
www.acmicpc.net
const fs = require('fs');
const input = fs.readFileSync("./dev/stdin").toString().trim().split('\n');
const N = +input[0]
const inequality = input[1].split(' ')
const answer = [];
function check(str,cnt){
if(cnt==N){
answer.push(str);
return;
}else{
const last = str[cnt];
if(inequality[cnt]=='>'){
for(let i = 0; i<10; i++){
if(!str.includes(`${i}`) && last>i){
check(str+`${i}`,cnt+1)
}
}
}else{
for(let i = 0; i<10; i++){
if(!str.includes(`${i}`) && last<i){
check(str+`${i}`,cnt+1)
}
}
}
}
}
for(let i = 0; i<10; i++){
check(`${i}`,0);
}
console.log(answer.pop()+'\n'+answer.shift())
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Node.js) 백준 4375번: 1 (0) | 2021.12.28 |
---|---|
Node.js) 백준 11052번: 카드 구매하기 (0) | 2021.12.27 |
Node.js) 백준 2217번: 로프 (0) | 2021.12.26 |
Node.js) 백준 2583번: 영역 구하기 (0) | 2021.12.26 |
Node.js) 백준 11727번: 2 × n 타일링 2 (0) | 2021.12.25 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 면접질문
- 롱베케이션
- DB 생성
- 동적프로그래밍
- 서버개발
- 투포인터
- node.js
- 은둔청년체험
- BFS
- 투포인터 연습
- 로드나인
- 그래프
- 서버점검
- create db
- 면접비
- create databases;
- 개발자면접
- 다이나믹프로그래밍
- 최소공통조상
- MOD
- MySQL
- 다이나밍프로그래밍
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함