https://programmers.co.kr/learn/courses/30/lessons/60058 코딩테스트 연습 - 괄호 변환 카카오에 신입 개발자로 입사한 "콘"은 선배 개발자로부터 개발역량 강화를 위해 다른 개발자가 작성한 소스 코드를 분석하여 문제점을 발견하고 수정하라는 업무 과제를 받았습니다. 소스를 programmers.co.kr #include #include #include using namespace std; bool isCorrect(string p){ stack s; for (char c: p){ if (c=='(') s.push(c); else{ if (s.empty()) return false; else s.pop(); } } return true; } string conver..
https://programmers.co.kr/learn/courses/30/lessons/77485 코딩테스트 연습 - 행렬 테두리 회전하기 6 6 [[2,2,5,4],[3,3,6,6],[5,1,6,3]] [8, 10, 25] 3 3 [[1,1,2,2],[1,2,2,3],[2,1,3,2],[2,2,3,3]] [1, 1, 5, 3] programmers.co.kr #include #include #include using namespace std; int matrix[101][101]; int move(int x1, int y1, int x2, int y2){ int x=x1; int y=y1; int temp=matrix[x1+1][y1]; int val; vector v; while (yx1){ va..
https://programmers.co.kr/learn/courses/30/lessons/12973# 코딩테스트 연습 - 짝지어 제거하기 짝지어 제거하기는, 알파벳 소문자로 이루어진 문자열을 가지고 시작합니다. 먼저 문자열에서 같은 알파벳이 2개 붙어 있는 짝을 찾습니다. 그다음, 그 둘을 제거한 뒤, 앞뒤로 문자열을 이어 붙 programmers.co.kr #include #include #include using namespace std; int solution(string s) { stack st; int pos=0; while (pos문자를 넣어주고 스택의 탑과 지금 넣으려는 애가 같으면->스택의 탑을 pop 해준다(짝지어 제거하는 방식) 서로 다르면=>그 문자를 push 해준다 다음 문자로 이..
https://programmers.co.kr/learn/courses/30/lessons/49189 코딩테스트 연습 - 가장 먼 노드 6 [[3, 6], [4, 3], [3, 2], [1, 3], [1, 2], [2, 4], [5, 2]] 3 programmers.co.kr #include #include #include #include #define MAX 987654321 using namespace std; class Node{ public: int id; int cost; Node(int id, int cost) : id(id), cost(cost) {} }; struct compare{ bool operator()(Node a, Node b){ return a.cost>b.cost; } }; ..
https://programmers.co.kr/learn/courses/30/lessons/42627 코딩테스트 연습 - 디스크 컨트롤러 하드디스크는 한 번에 하나의 작업만 수행할 수 있습니다. 디스크 컨트롤러를 구현하는 방법은 여러 가지가 있습니다. 가장 일반적인 방법은 요청이 들어온 순서대로 처리하는 것입니다. 예를 programmers.co.kr #include #include #include #include using namespace std; struct Job{ int request, time; Job(int request, int time) : request(request), time(time) {} }; struct compare{ bool operator()(Job a, Job b){ r..
https://programmers.co.kr/learn/courses/30/lessons/43165 코딩테스트 연습 - 타겟 넘버 n개의 음이 아닌 정수가 있습니다. 이 수를 적절히 더하거나 빼서 타겟 넘버를 만들려고 합니다. 예를 들어 [1, 1, 1, 1, 1]로 숫자 3을 만들려면 다음 다섯 방법을 쓸 수 있습니다. -1+1+1+1+1 = 3 +1-1+1+1+ programmers.co.kr #include #include using namespace std; int cnt=0; void dfs(vector& numbers, int target, int depth, int limit, int result){ if (depth==limit){ if (result==target){ cnt++; } r..
https://programmers.co.kr/learn/courses/30/lessons/42839 코딩테스트 연습 - 소수 찾기 한자리 숫자가 적힌 종이 조각이 흩어져있습니다. 흩어진 종이 조각을 붙여 소수를 몇 개 만들 수 있는지 알아내려 합니다. 각 종이 조각에 적힌 숫자가 적힌 문자열 numbers가 주어졌을 때, 종이 programmers.co.kr #include #include #include #include #define MAX 8 using namespace std; bool check[MAX]={false,}; int sieves[10000000]; set ans; void primenumSieve(int num){ sieves[0]=0; sieves[1]=0; for (int i=2..
https://www.acmicpc.net/problem/16236 16236번: 아기 상어 N×N 크기의 공간에 물고기 M마리와 아기 상어 1마리가 있다. 공간은 1×1 크기의 정사각형 칸으로 나누어져 있다. 한 칸에는 물고기가 최대 1마리 존재한다. 아기 상어와 물고기는 모두 크기를 가 www.acmicpc.net #include using namespace std; int dy[4]={0,0,1,-1}; int dx[4]={1,-1,0,0}; int space[20][20]; int minVal=987654321; class Pos{ public: int y; int x; int cnt; Pos(int y, int x, int cnt){ this->y=y; this->x=x; this->cnt=cn..
https://programmers.co.kr/learn/courses/30/lessons/1835 코딩테스트 연습 - 단체사진 찍기 단체사진 찍기 가을을 맞아 카카오프렌즈는 단체로 소풍을 떠났다. 즐거운 시간을 보내고 마지막에 단체사진을 찍기 위해 카메라 앞에 일렬로 나란히 섰다. 그런데 각자가 원하는 배치가 모두 programmers.co.kr #include #include #include #include using namespace std; int solution(int n, vector data) { int answer = 0; vector v={'A', 'C', 'F', 'J', 'M', 'N', 'R', 'T'}; do{ vector temp; vector::iterator it1; vect..
https://programmers.co.kr/learn/courses/30/lessons/72410 코딩테스트 연습 - 신규 아이디 추천 카카오에 입사한 신입 개발자 네오는 "카카오계정개발팀"에 배치되어, 카카오 서비스에 가입하는 유저들의 아이디를 생성하는 업무를 담당하게 되었습니다. "네오"에게 주어진 첫 업무는 새로 programmers.co.kr #include #include #include using namespace std; string solution(string new_id) { string answer = ""; string answer1 = ""; for (int i=0; i