Study/Programmers (19) 썸네일형 리스트형 프로그래머스 - 문자열 압축(2020 KAKAO BLIND RECRUITMENT) 시험 기간이라 짬나는 대로 한 문제씩 풀어보기로 하였다. 코드 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 #include #include #include using namespace std; int solution(string s) { int answer = 0; int cnt = 0; answer = s.size(); for(int size = 1; size 프로그래머스 - 메뉴 리뉴얼(2021 KAKAO BLIND RECRUITMENT) 주문한 메뉴(string)에 대해 course 메뉴의 개수만큼(2, 3, 4 ...) substring을 구하여 vector에 저장한 뒤, 가장 많이 주문한 코스 메뉴 조합을 answer에 추가하여 return하면 된다. 코드 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 #include #include #include #include #include using namespace std; map m; vector v; vector solution(vector orders, vector cou.. 프로그래머스 - 신규 아이디 추천(2021 KAKAO BLIND RECRUITMENT) String을 이용한 구현문제였다. String에 대한 표준함수들을 많이 알 수록 이 문제를 더 쉽게 풀 수 있었던 것 같다. 코드 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 #include #include #include #include using namespace std; string my_lowcase(string s) { for(int i=0; i= 'A' && s[i] 프로그래머스 - 합승 택시 요금(2021 KAKAO BLIND RECRUITMENT) 코드 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 31 32 33 34 35 36 37 #include #include #include #include using namespace std; int cost[201][201]; int INF = 10000000; int solution(int n, int s, int a, int b, vector fares) { int answer = 0; for(int i=1; i 프로그래머스 - 순위 코드 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 #include #include #include using namespace std; bool graph[101][101]; int solution(int n, vector results) { int answer = 0; memset(graph, false, sizeof(graph)); //cstring 헤더 추가 for(int i=0; i 프로그래머스 - 섬 연결하기 두 Vertex를 잇는 Edge의 cost가 주어졌고, 해당 cost가 최소인 MST를 만드는 것이 문제의 목표이다. MST를 구하는 방법은 여러 개가 있는데, 이 중 Kruskal-algorithm을 사용하여 풀어보도록 하겠다. 크루스칼 알고리즘은 union-find 알고리즘을 이용하여 MST를 구하는 알고리즘으로 잘 알려져 있다. 코드 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 #include #include #include using namespace std; int getRoot(int idx, .. 프로그래머스 - 여행 경로 TC 1번을 제외하고는 쉽게 풀렸는데 1번이 너무~너무 안풀려서 많이 헤맨 문제이다. 참고한 코드 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 31 32 33 34 #include #include using namespace std; int visited[1000000]; string ans_string = "a"; void dfs(vector &tickets, string cur, string path, int depth) { if (depth == tickets.size()) { string p = path; if (path 프로그래머스 - 단어 변환 DFS를 이용하여 풀었는데, 사실 처음에 생각했던 BFS를 이용해서도 풀 수 있는 것 같다. 코드 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 #include #include #include #include using namespace std; int visit[51]; int res = 987654321; int check(string a, string b) { int cnt = 0; for(int i=0; i words.size()) return ; if (begin == target) { res = min(res, .. 이전 1 2 3 다음