전체 글 79

프로그래머스, C++) Lv 2. 괄호 회전하기

문제https://school.programmers.co.kr/learn/courses/30/lessons/76502 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 접근법1. 문자열 길이 2배2. 슬라이딩 윈도우 개념처럼 l과 r로 접근하여 구간별 체크 => 맞음3. 여는 괄호, 닫는 괄호의 순서와 카운팅으로 체크하려 했으나 반례가 너무 많음. 반례: ( [ ) ] 원래 접근법인 코드더보기#include #include using namespace std; /* 칸 회전 -> 즉, 맨 앞을 맨 뒤로 보내고 문자열 체크 doubleS -> [](){}[](){} */ int solution(stri..

프로그래머스, C++) Lv 2. 연속 부분 수열 합의 개수

문제https://school.programmers.co.kr/learn/courses/30/lessons/131701?language=cpp 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 슬라이딩 윈도우 기법 -> 슬라이딩 윈도우라는 것을 알았지만, 구현을 실패,, -> GPT 도움더보기#include #include #include #include #include using namespace std; /* 슬라이딩 윈도우 적용*/ int solution(vector elements) { int n = elements.size(); unordered_set sums; /..

프로그래머스, C++) Lv 2. 예상 대진표

문제https://school.programmers.co.kr/learn/courses/30/lessons/12985 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 틀린 코드 -> while문의 종료조건 때문에 시간 초과가 나는 테스트 케이스들이 존재더보기#include using namespace std; /* while문으로 계속 2로 나눈 몫으로 a,b의 숫자가 유지됨. + 항상 이긴다고 가정 -> 안만나는 경우는 x 출력 : round */ int solution(int n, int a, int b) { int round = 1; // 라운드 if(a>b) swap(a,b..

프로그래머스, C++) Lv 2. 기능개발

문제https://school.programmers.co.kr/learn/courses/30/lessons/42586 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 더보기#include #include #include using namespace std; /* - progresses 작업 진도 - speed 작업 속도 만약 앞의 순서 작업이 안 끝났다면, 뒷 순서 progress도 배포 X 한 번에 배포되는 기능의 수. 5 1 1 6 1 7 8 */ vector solution(vector progresses, vector speeds) { vector answer; // 날짜 ..

프로그래머스, C++) Lv 2. 프로세스

문제https://school.programmers.co.kr/learn/courses/30/lessons/42587 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 같은 우선 순위의 값들을 구분하기 위해 queue를 pair의 형태로 생성해 index까지 저장하게 함.priority_queue를 통해 우선순위가 가장 큰 것을 설정 - top에 접근더보기#include #include #include #include #include using namespace std; /* Location의 해당하는 프로세스가 실행되는 순서는 무엇인가 priorities가 큰 순서로 실행됨. */ int solutio..

프로그래머스, C++) Lv 2. 피로도

문제https://school.programmers.co.kr/learn/courses/30/lessons/87946?language=cpp 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 기존의 dfs와 동일하나 백트레킹이라는 개념이 추가됨dfs의 경우, visited배열을 통해 갔던 곳을 안가게 함.그러나 '피로도'의 경우, 가능한 모든 경우의 수를 전부 체크하기 때문에 재귀가 끝난 후, 다시 visited[i] = false 처리를 통해 모든 경우의 수 탐색 dfs와 재귀 기반의 코드 더보기#include using namespace std; int answer = 0; void dfs(int fatigu..

프로그래머스, C++) Lv 2. 의상

문제https://school.programmers.co.kr/learn/courses/30/lessons/42578 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 해시 문제unordered_map을 통해 key에 대한 value를 업데이트이미 key가 있는 경우, 자동적으로 value가 업데이트 됨.set을 이용하려 했으나, key가 중복될 우려가 있어 불가더보기#include #include #include #include using namespace std; /* 의상 종류(key) : 의상 가짓수(value) */ int solution(vector> clothes) { unordere..

프로그래머스, C++) Lv 2. 게임 맵 최단거리

DFS로는 최단 거리를 구할 수 없음BFS로 가능 + 상하좌우 라는 방향을 추가더보기#include using namespace std; int solution(vector> maps) { int n = maps.size(); int m = maps[0].size(); vector> dist(n, vector(m, 0)); // 0: 미방문, 그 외: 거리 queue> q; // 이동 방향(상, 하, 좌, 우) int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; // 시작점 (0,0) 이 1(통로)인지 확인 if (maps[0][0] == 0) return -1; // 시작 설정 ..

카테고리 없음 2025.10.23

프로그래머스, C++) Lv 3. 네트워크

문제https://school.programmers.co.kr/learn/courses/30/lessons/43162 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr DFS / BFS 둘다 가능 DFS 버전더보기#include #include using namespace std; void dfs(int node, vector>& computers, vector& visited, int n) { visited[node] = true; // 현재 노드 방문 표시 for (int i = 0; i // 자기 자신이 아니면서, 연결되어 있고, 아직 방문 안 한 경우 if (..

프로그래머스, C++) Lv 2. 영어 끝말잇기

문제https://school.programmers.co.kr/learn/courses/30/lessons/12981 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 문제 적힌 것을 그대로 체크하면 됨단, 턴 계산을 잘해야 됨. 더보기#include #include #include #include using namespace std; /* 가장 먼저 탈락하는 사람의 번호 + 그 사람의 몇 번째 차례일 때 탈락하는 지 1. 앞 단어의 마지막 알파벳과 지금 단어의 첫 알파벳을 체크. -> 다르면 탈락 2. 탈락하지 않는 경우도 존재. */ vector solution(int n, vector words)..