https://programmers.co.kr/learn/courses/30/lessons/64064
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<vector<int>> tmp;
int answer = 0;
vector<vector<int>> num;
void FindAnswer(int index, vector<int> v) {
if (index == num.size()) {
sort(v.begin(), v.end());
if (find(tmp.begin(), tmp.end(), v) == tmp.end()) {
tmp.push_back(v);
}
return;
}
for (int i = 0; i<num[index].size(); i++) {
if (find(v.begin(), v.end(), num[index][i]) == v.end()) {
v.push_back(num[index][i]);
FindAnswer(index + 1, v);
v.pop_back();
}
else {
continue;
}
}
}
int solution(vector<string> user_id, vector<string> banned_id) {
num.resize(banned_id.size());
for (int i = 0; i<user_id.size(); i++) {
for (int j = 0; j<banned_id.size(); j++) {
int index = 0;
if (user_id[i].size() != banned_id[j].size())
continue;
while (index < user_id[i].size() && (user_id[i][index] == banned_id[j][index] || banned_id[j][index] == '*')) {
index++;
}
if (index == banned_id[j].size()) {
num[j].push_back(i);
}
}
}
vector<int> v;
FindAnswer(0, v);
answer = tmp.size();
return answer;
}
'프로그래머스' 카테고리의 다른 글
셔틀버스 C++ (0) | 2021.10.03 |
---|---|
다단계 칫솔 C++ (0) | 2021.10.03 |
자물쇠와 열쇠 C++ (0) | 2021.08.22 |
매출 하락 최소화 C++ (0) | 2021.08.09 |
괄호 변환 C++ (0) | 2021.08.08 |