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
- 디자인 패턴
- 브릿지 패턴
- 컴포지트
- 흐름식 빌더
- 브릿지
- 프로토타입 패턴
- 싱글톤
- 빌더 패턴
- 팩터리 메서드
- 빌더
- 동적 데커레이터
- 추상 팩터리
- 싱글턴
- 내부 팩터리
- 팩터리 패턴
- 함수형 팩터리
- 모던C++디자인패턴
- 프로토타입 중복처리
- 싱글턴 패턴
- 싱글톤 패턴
- 컴포지트 패턴
- 동적 데코레이터
- 컴포지트 빌더
- 데커레이터 패턴
- 그루비 스타일 빌더
- 팩터리
- 디자인패턴
- 프로토타입
- 데커레이터
- 단순한 빌더
Archives
- Today
- Total
GGym's Practice Notes
프로그래머스 Level2_ 스킬 트리 (C++) 본문
스킬트리에 들어가 있는 문자를 체크하고 Queue를 이용해 스킬트리의 순서를 검사한다.
#include <string> // Level2_ 스킬트리 [큐]
#include <vector>
#include <string.h>
#include <queue>
#include <iostream>
using namespace std;
int solution(string skill, vector<string> skill_trees) {
int answer = 0;
queue<char> oq;
bool is_prior[26];
memset(is_prior, false, sizeof(char)*26);
for(auto ch : skill){
oq.push(ch);
is_prior[ch-'A'] = true;
}
for(int i= 0; i<skill_trees.size(); i++){
queue<char> cq = oq;
bool is_possible = true;
for(auto ch : skill_trees[i]){
if(is_prior[ch-'A']){
if(cq.front() == ch){
cq.pop();
}
else{
is_possible = false;
break;
}
}
}
if(is_possible) answer++;
}
return answer;
}
int main(){
string skill;
vector<string> skill_trees;
int n;
cin >>n;
cin >> skill;
for(int i=0; i<n; i++){
string s;
cin >> s;
skill_trees.push_back(s);
}
cout << solution(skill, skill_trees);
}
'Algorithm' 카테고리의 다른 글
프로그래머스 Level1_ 크레인 인형뽑기 게임 (C++) (0) | 2020.10.08 |
---|---|
프로그래머스 Level2_ 주식가격 (C++) (0) | 2020.10.08 |
프로그래머스 Level2_ 조이스틱 (C++) (0) | 2020.10.08 |
프로그래머스 Level3_ 단어 변환 (C++) (0) | 2020.10.08 |
프로그래머스 Level2_ 다리를 지나는 트럭 (C++) (0) | 2020.10.08 |