프로그래머스
스킬트리 C++
by paysmile
2019. 10. 23.
#include <string>
#include <vector>
#include <map>
#include <algorithm>]
using namespace std;
int solution(string skill, vector<string> skill_trees) {
int answer = 0;
map<char, int> m;
for (int i = 1; i <= skill.length(); i++) {
m[skill[i - 1]] = i;
}
for (int i = 0; i < skill_trees.size(); i++) {
int index = 1;
bool flag = true;
for (int j = 0; j < skill_trees[i].size(); j++) {
if (m[skill_trees[i][j]] != 0) {
if (m[skill_trees[i][j]] > index) {
flag = false;
break;
}
else {
if(m[skill_trees[i][j]] == index)
index++;
}
}
}
if (flag == true) {
answer++;
cout << "성공" << endl;
}
}
return answer;
}