본문 바로가기

개발90

[프로그래머스 Lv3 C++] 정수 삼각형 안녕하십니까. Eun🦆입니다. 풀이법 입니다. 코딩테스트 연습 - 정수 삼각형 [[7], [3, 8], [8, 1, 0], [2, 7, 4, 4], [4, 5, 2, 6, 5]] 30 programmers.co.kr [시간 초과, DFS로 푼 코드] // 처음 DFS로 완벽하게 풀었다고 좋아했는데... 아쉬운 결과 #include #include using namespace std; int answer = 0; void DFS(vector triangle, int sum, int y, int x) { if(y>=triangle.size()-1) { if(sum > answer) answer = sum; return; } DFS(triangle, sum+triangle[y+1][x], y+1, x); DF.. 2022. 6. 7.
[프로그래머스 Lv3 C++] 단속카메라 안녕하십니까. Eun🦆입니다. 풀이법 입니다. 코딩테스트 연습 - 단속카메라 [[-20,-15], [-14,-5], [-18,-13], [-5,-3]] 2 programmers.co.kr #include #include #include using namespace std; int solution(vector routes) { int answer = 0; // 1. 차량이 서로 만나는 경우 겹치는 위치의 가장 뒤에 카메라를 둔다 // 2. 차량이 만나지 않는 경우엔 카메라 개수를 증가시키고 뒤 차량의 가장 뒤에 카메라를 둔다 sort(routes.begin(), routes.end()); int camera = routes[0][1]; answer++; for(int i=1;i routes[i][1]) c.. 2022. 6. 7.
[프로그래머스 Lv3 C++] 네트워크 안녕하십니까. Eun🦆입니다. 풀이법 입니다. 코딩테스트 연습 - 네트워크 네트워크란 컴퓨터 상호 간에 정보를 교환할 수 있도록 연결된 형태를 의미합니다. 예를 들어, 컴퓨터 A와 컴퓨터 B가 직접적으로 연결되어있고, 컴퓨터 B와 컴퓨터 C가 직접적으로 연결되어 있 programmers.co.kr #include #include using namespace std; int answer = 0; bool visit[200] = {0,}; void BFS(int i, int n, vector computers) // 처음 네트워크 그룹부터 방문한 네트워크 모두 visit 처리 { visit[i] = 1; printf("visit[i=%d]=%d\n",i,visit[i]); for(int j=0;j 2022. 6. 7.
[프로그래머스 C++] 더 맵게 안녕하십니까. Eun🦆입니다. 효율성 시간초과 [C++/문제풀이] C++을 무기로, 코딩테스트 광탈을 면하자! - Step3: 풀어서 내걸로 만들자! "더 맵게" × 잠깐! 이건 C++ 버전의 강의에요. 본 강의는 동일한 문제 풀이 내용을 Python 기반으로 진행하는 버전도 존재합니다. 만약 C++ 은 전혀 모르고, Python 으로 코딩테스트를 준비하고 있다면 여기를 눌 programmers.co.kr #include #include #include using namespace std; int solution(vector scoville, int K) { int answer = 0; sort(scoville.begin(),scoville.end()); while(scoville[0] 1) { answ.. 2022. 6. 7.
[프로그래머스 C++] 가장 큰 수 안녕하십니까. Eun🦆입니다. 풀이법 입니다. b+a; // 큰 수를 왼쪽에 정렬 } string solution(vector numbers) { string answer = ""; vector arr; for(int i=0;i 2022. 6. 7.
[프로그래머스 C++ Lv2] 압축 안녕하십니까. Eun🦆입니다. 풀이법 입니다. 코딩테스트 연습 - [3차] 압축 TOBEORNOTTOBEORTOBEORNOT [20, 15, 2, 5, 15, 18, 14, 15, 20, 27, 29, 31, 36, 30, 32, 34] programmers.co.kr #include #include #include using namespace std; vector solution(string msg) { vector answer; int cnt = 0; map dic; // key 단어, value 출력 for(;cnt 2022. 6. 7.