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++
- 참고 문헌 : MACHINE LEARNING 기계학습 _ 오일석
- 시스템콜
- vector
- 정렬
- String
- Dijkstra
- MAP
- 동적계획법
- 최대공약수
- unordered_map
- sql고득점kit
- 백준
- 코딩테스트연습
- 코테
- 문자열
- 스택
- set
- dfs
- 리시프
- 다익스트라
- DP
- 프로그래머스
- 알고리즘
- substr
- MySQL
- 다이나믹프로그래밍
Archives
- Today
- Total
YeJin's Footsteps
불량사용자 본문
https://programmers.co.kr/learn/courses/30/lessons/64064
코딩테스트 연습 - 불량 사용자
개발팀 내에서 이벤트 개발을 담당하고 있는 "무지"는 최근 진행된 카카오이모티콘 이벤트에 비정상적인 방법으로 당첨을 시도한 응모자들을 발견하였습니다. 이런 응모자들을 따로 모아 불량
programmers.co.kr
문제 코드 풀이
#include <string>
#include <vector>
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
set <string> s;
bool visited[8];
bool matched(string user, string ban){
if(user.length()!=ban.length()) return false;
else{
for(int i=0; i<user.length(); i++){
if(ban[i]=='*' || ban[i]==user[i]) continue;
else return false;
}
return true;
}
}
void dfs(int n, vector<int> check, vector<string> user, vector<string> ban){
if(n==ban.size()){
sort(check.begin(), check.end());
string in;
for(int i=0; i<check.size() ;i++) in+=to_string(check[i]);
s.insert(in);
return;
}
for(int i=0; i<user.size(); i++){
if(matched(user[i],ban[n])&&!visited[i]){
check.push_back(i);
visited[i]=true;
dfs(n+1, check, user, ban);
visited[i]=false;
check.pop_back();
}
}
}
int solution(vector<string> user_id, vector<string> banned_id) {
for(int i=0; i<8; i++) visited[i]=false;
int answer = 0;
vector <int> check;
dfs(0, check, user_id, banned_id);
answer = s.size();
return answer;
}
'Computer Science & Engineering > 알고리즘' 카테고리의 다른 글
H-Index (0) | 2021.07.01 |
---|---|
가장 큰 수 (0) | 2021.07.01 |
신규 아이디 추천 (0) | 2021.05.02 |
튜플 (0) | 2021.05.02 |
크레인 인형 뽑기 게임 (0) | 2021.05.02 |