본문 바로가기
728x90

알고리즘/프로그래머스68

알고리즘(C++) / 프로그래머스 level 3 : 여행경로 level 3 : 여행경로 https://programmers.co.kr/learn/courses/30/lessons/43164?language=cpp 코딩테스트 연습 - 여행경로 [["ICN", "SFO"], ["ICN", "ATL"], ["SFO", "ATL"], ["ATL", "ICN"], ["ATL","SFO"]] ["ICN", "ATL", "ICN", "SFO", "ATL", "SFO"] programmers.co.kr 코드 //프로그래머스 여행경로 #include #include #include using namespace std; vector tickets_copy; bool visited[10001] = { false, }; vector answer; bool check = false; v.. 2021. 8. 11.
알고리즘(C++) / 프로그래머스 level 3 : 순위 level 3 : 순위 https://programmers.co.kr/learn/courses/30/lessons/49191?language=cpp 코딩테스트 연습 - 순위 5 [[4, 3], [4, 2], [3, 2], [1, 2], [2, 5]] 2 programmers.co.kr 코드 //프로그래머스 순위 #include #include #include using namespace std; int solution(int n, vector results) { int answer = 0; int graph[101][101] = { false, }; for (int i = 0; i < results.size(); i++) { graph[results[i][0]][results[i][1]] = 1; // .. 2021. 8. 9.
알고리즘(C++) / 프로그래머스 level 3 : 입국심사 level 3 : 입국심사 https://programmers.co.kr/learn/courses/30/lessons/43238?language=cpp 코딩테스트 연습 - 입국심사 n명이 입국심사를 위해 줄을 서서 기다리고 있습니다. 각 입국심사대에 있는 심사관마다 심사하는데 걸리는 시간은 다릅니다. 처음에 모든 심사대는 비어있습니다. 한 심사대에서는 동시에 한 programmers.co.kr 코드 //프로그래머스 입국심사 #include #include #include #include using namespace std; long long solution(int n, vector times) { long long answer = 0; sort(times.begin(), times.end()); long.. 2021. 8. 6.
알고리즘(C++) / 프로그래머스 level 2 : 후보키 level 2 : 후보키 https://programmers.co.kr/learn/courses/30/lessons/42890?language=cpp 코딩테스트 연습 - 후보키 [["100","ryan","music","2"],["200","apeach","math","2"],["300","tube","computer","3"],["400","con","computer","4"],["500","muzi","music","3"],["600","apeach","music","2"]] 2 programmers.co.kr 코드 #include #include #include #include using namespace std; vector ans; // 최소성 확인 bool possi(int now) { for.. 2021. 8. 5.
알고리즘(C++) / 프로그래머스 level 2 : 파일명 정렬 level 2 : 파일명 정렬 https://programmers.co.kr/learn/courses/30/lessons/17686?language=cpp 코딩테스트 연습 - [3차] 파일명 정렬 파일명 정렬 세 차례의 코딩 테스트와 두 차례의 면접이라는 기나긴 블라인드 공채를 무사히 통과해 카카오에 입사한 무지는 파일 저장소 서버 관리를 맡게 되었다. 저장소 서버에는 프로그램 programmers.co.kr 코드 //프로그래머스 파일명 정렬 #include #include #include #include #include using namespace std; bool cmp(vector a, vector b) { if (a[0] != b[0]) { return a[0] < b[0]; } else { re.. 2021. 8. 4.
알고리즘(c++) / 프로그래머스 level 3 : 네트워크 level 3 : 네트워크 https://programmers.co.kr/learn/courses/30/lessons/43162 코딩테스트 연습 - 네트워크 네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있 programmers.co.kr 코드 //프로그래머스 네트워크 #include #include #include using namespace std; vector computers_copy; bool visited[201] = { false, }; void DFS(int node) { visited[node] = true; //방문한 노드 for (int i = .. 2021. 8. 2.
알고리즘(C++) / 프로그래머스 level 3 : 단어 변환 level 3 : 단어 변환 https://programmers.co.kr/learn/courses/30/lessons/43163 코딩테스트 연습 - 단어 변환 두 개의 단어 begin, target과 단어의 집합 words가 있습니다. 아래와 같은 규칙을 이용하여 begin에서 target으로 변환하는 가장 짧은 변환 과정을 찾으려고 합니다. 1. 한 번에 한 개의 알파벳만 바꿀 수 programmers.co.kr 코드 //프로그래머스 단어 변환 #include #include #include #include #include #include using namespace std; vector words_copy; //알파벳 하나만 다를때: true, else: false bool compare(strin.. 2021. 8. 1.
알고리즘(C++) / 프로그래머스 level 2 : 123 나라의 숫자 level 2 : 123 나라의 숫자 https://programmers.co.kr/learn/courses/30/lessons/12899?language=cpp 코딩테스트 연습 - 124 나라의 숫자 programmers.co.kr 코드 //프로그래머스 124나라의 숫자 #include #include #include using namespace std; string solution(int n) { string answer = ""; while (n) { n--; if (n % 3 == 0) { answer = "1" + answer; } else if (n % 3 == 1) { answer = "2" + answer; } else { answer = "4" + answer; } n /= 3; } re.. 2021. 7. 28.
알고리즘(C++) / 프로그래머스 level 2 : 짝지어 제거하기 level 2 : 짝지어 제거하기 https://programmers.co.kr/learn/courses/30/lessons/12973?language=cpp 코딩테스트 연습 - 짝지어 제거하기 짝지어 제거하기는, 알파벳 소문자로 이루어진 문자열을 가지고 시작합니다. 먼저 문자열에서 같은 알파벳이 2개 붙어 있는 짝을 찾습니다. 그다음, 그 둘을 제거한 뒤, 앞뒤로 문자열을 이어 붙 programmers.co.kr 코드 #include #include #include //first in last out using namespace std; int solution(string s) { int answer = -1; stack st; for (int i = 0; i < s.size(); i++) { if (.. 2021. 7. 26.
알고리즘(C++) / 프로그래머스 level 2 : 기능 개발 level 2 : 기능 개발 https://programmers.co.kr/learn/courses/30/lessons/42586?language=cpp 코딩테스트 연습 - 기능개발 프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다. 또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는 programmers.co.kr 코드 //프로그래머스 기능 개발 #include #include #include using namespace std; vector solution(vector progresses, vector speeds) { vector answer; vector day; for (int i = 0; i < progr.. 2021. 7. 25.
알고리즘(C++) / 프로그래머스 level 2 : 멀쩡한 사각형 level 2 : 멀쩡한 사각형 https://programmers.co.kr/learn/courses/30/lessons/62048?language=cpp 코딩테스트 연습 - 멀쩡한 사각형 가로 길이가 Wcm, 세로 길이가 Hcm인 직사각형 종이가 있습니다. 종이에는 가로, 세로 방향과 평행하게 격자 형태로 선이 그어져 있으며, 모든 격자칸은 1cm x 1cm 크기입니다. 이 종이를 격자 선을 programmers.co.kr 코드 //프로그래머스 멀쩡한 사각형 #include using namespace std; int GCD(int w, int h) { if (w % h == 0) return h; return GCD(h, w % h); } long long solution(int w, int h) .. 2021. 7. 24.
알고리즘(C++) / 프로그래머스 level 2 : 뉴스 클러스터링 level 2 : 뉴스 클러스터링 https://programmers.co.kr/learn/courses/30/lessons/17677?language=cpp 코딩테스트 연습 - [1차] 뉴스 클러스터링 뉴스 클러스터링 여러 언론사에서 쏟아지는 뉴스, 특히 속보성 뉴스를 보면 비슷비슷한 제목의 기사가 많아 정작 필요한 기사를 찾기가 어렵다. Daum 뉴스의 개발 업무를 맡게 된 신입사원 튜브 programmers.co.kr 코드 //프로그래머스 뉴스 클러스터링 #include #include #include #include using namespace std; int solution(string str1, string str2) { int answer = 0; vector s1; vector s2; //.. 2021. 7. 21.