[프로그래머스] 사칙연산(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/1843 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include #include int max_val = std::numeric_limits::max();int min_val = std::numeric_limits::min();using namespace std;int solution(vector arr){ int n = (arr.size() + 1) / 2; // 숫자 개수 vector nums; vector ops; for (..
[프로그래머스] 단속카메라(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/42884 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include #include using namespace std;bool Compare(const vector& a, const vector& b){ return a[1] > routes) { int answer = 1; // 진출 시점 기준으로 오름차순 정렬 sort(routes.begin(), routes.end(), Compare); int out = rout..
[프로그래머스] 이중우선순위큐(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/42628 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include #include using namespace std;vector solution(vector operations){ // 이중우선순위큐 multiset 이용 std::multiset dq; for (const auto& op : operations) { // 삽입 if (op[0] == 'I') { int ..
[프로그래머스] 정수 삼각형(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/43105 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include using namespace std;int solution(vector> triangle){ int n = triangle.size(); vector> dp(n, vector(n, 0)); // dp 테이블 맨 아랫쪽 초기화 for (int i = 0; i = 0; --i) { for (int j = 0; j 해결 방법거쳐간 숫자의 최댓값을 구..
[프로그래머스] 단어 변환(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/43163 프로그래머스SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include #include using namespace std;bool IsNeighbor(const string& a, const string& b){ // 두 단어를 비교하여 하나만 단어가 다른 경우를 찾음 int diff = 0; for (int i = 0; i 1) return false; } return true;}int solution(string begin..
[프로그래머스] 가장 먼 노드(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/49189 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include #include using namespace std;vector> graph;vector visited;queue q;void bfs(int start){ visited[start] = 1; q.push(1); while (!q.empty()) { int now = q.front(); q.pop(); for (int n..
[프로그래머스] 길 찾기 게임(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/42892 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include using namespace std;// 노드 정의struct Node{ int id, x, y; Node* left = nullptr; Node* right = nullptr; Node(int _id, int _x, int _y) : id(_id) , x(_x) , y(_y) {}};// 이진 트리 정의class..
[프로그래머스] n개의 최소공배수(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/12953 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include using namespace std;bool isValid(const vector& arr, int num){ for (int i = 0; i arr){ int answer = 0; int max = 0; for (int i = 0; i = max) max = arr[i]; } int i = 1; while (true) { ..
[프로그래머스] 전력망을 둘로 나누기(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/86971 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include #include using namespace std;vector> tree;vector visited;int nodeCount = 0;void dfs(int node){ nodeCount++; for (const auto& neighbor : tree[node]) { if (!visited[neighbor]) { vi..
[프로그래머스] 네트워크(C++)
·
카테고리 없음
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/43162 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include using namespace std;// 모든 컴퓨터가 간접적으로 연결되어 있으면 하나의 네트워크// dfs 로 방문체크 하면서 순환 -> dfs 횟수 = 네트워크 개수bool visited[200];int answer = 0;void dfs(const vector>& computers, int startNode){ if (visited[startNode] == true)..
[프로그래머스] 하노이의 탑(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/12946 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 풀이#include #include #include using namespace std;vector> answer;// 원판 개수, 시작 기둥, 보조 기둥, 목적지 기둥void Hanoi(int n, int start, int via, int dest){ if (n == 1) { answer.push_back({ start, dest }); return; } Hanoi(n -..
[프로그래머스] 타겟 넘버(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/43165 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include using namespace std;int answer = 0;void dfs(const vector& numbers, int _Index, int _sum, const int& _target){ if (_Index == numbers.size()) { if (_sum == _target) answer++; return; } ..
[프로그래머스] 미로 탈출(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/159993 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include #include using namespace std;struct Point{ int y, x; int score; bool operator==(const Point& other) const { return y == other.y && x == other.x; } Point operator+(const Point& other) con..
[프로그래머스] 게임 맵 최단거리(C++)
·
개발/알고리즘
문제 링크https://school.programmers.co.kr/learn/courses/30/lessons/1844 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 코드 구현#include #include #include using namespace std;struct Point{ int y, x; Point operator+(const Point& other) const { return Point(y + other.y, x + other.x); } bool operator==(const Point& other) const { if..