Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- rpg server
- screencapture
- spread 연산자
- SDK upgrade
- Google Developer API
- Camera Movement
- express
- Spring Boot
- Packet Network
- springboot
- Unity IAP
- css framework
- Google Refund
- linux
- react
- critical rendering path
- java
- draganddrop
- Unity Editor
- --watch
- Git
- nodejs
- MySQL
- server
- OverTheWire
- docker
- Camera Zoom
- mongoDB
- Digital Ocean
- unity
Archives
- Today
- Total
우당탕탕 개발일지
[프로그래머스] Level 2. 모음사전 본문
https://school.programmers.co.kr/questions/80728
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
사전순으로찾다가, 내가 원하는 글자가 나오면 멈춘다. 문제는 사전순서대로 어떻게찾냐인듯.
dfs를 이용해서 푼다. dfs 의 반환형이 void 가 아니라 boolean인 이유는, 원하는 단어를 찾았는지 안찾았는지를 판별하기 위함이다.
탐색순서는 다음처럼 진행된다
A [] [] [] []
A A [] [] []
A A A [] []
A A A A []
A A A A A
A A A A E
A A A A I
A A A A O
A A A A U
A A A E []
A A A E A
...
#include <string>
#include <vector>
using namespace std;
string vowel ="AEIOU";
string word;
int answer = 0;
bool dfs(int idx, string str){
if(idx == 5) return false;
for(auto ch: vowel){
answer++;
if(str+ch == word) return true;
if(dfs(idx+1,str+ch))return true;
}
return false;
}
int solution(string word) {
::word = word;
dfs(0,"");
return answer;
}
'Algorithm(c++) > Level 2' 카테고리의 다른 글
[프로그래머스] Level 2. 2 x n 타일링 (0) | 2025.02.25 |
---|---|
[프로그래머스] Level 2. 땅따먹기 (0) | 2025.02.24 |
[프로그래머스] Level 2. 뉴스 클러스터링 (0) | 2025.02.21 |
[프로그래머스] Level 2. 프로세스 (0) | 2025.02.20 |
[프로그래머스] Level 2. 점프와 순간이동 (0) | 2025.02.19 |