본문 바로가기
728x90

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

프로그래머스(C++) / level 2 : 단체사진 찍기 level 2 : 단체사진 찍기 https://programmers.co.kr/learn/courses/30/lessons/1835?language=cpp 코딩테스트 연습 - 단체사진 찍기 단체사진 찍기 가을을 맞아 카카오프렌즈는 단체로 소풍을 떠났다. 즐거운 시간을 보내고 마지막에 단체사진을 찍기 위해 카메라 앞에 일렬로 나란히 섰다. 그런데 각자가 원하는 배치가 모두 programmers.co.kr 🎨 문제 가을을 맞아 카카오프렌즈는 단체로 소풍을 떠났다. 즐거운 시간을 보내고 마지막에 단체사진을 찍기 위해 카메라 앞에 일렬로 나란히 섰다. 그런데 각자가 원하는 배치가 모두 달라 어떤 순서로 설지 정하는데 시간이 오래 걸렸다. 네오는 프로도와 나란히 서기를 원했고, 튜브가 뿜은 불을 맞은 적이 있던 .. 2022. 2. 3.
프로그래머스(MySQL) / IS NULL(이름이 없는 동물의 아이디, 이름이 있는 동물의 아이디, NULL 처리하기) IS NULL(이름이 없는 동물의 아이디, 이름이 있는 동물의 아이디, NULL 처리하기) 링크를 누르면 각 문제로 이동합니다! 이름이 없는 동물의 아이디 이름이 있는 동물의 아이디 NULL 처리하기 이름이 없는 동물의 아이디 https://programmers.co.kr/learn/courses/30/lessons/59039 코딩테스트 연습 - 이름이 없는 동물의 아이디 ANIMAL_INS 테이블은 동물 보호소에 들어온 동물의 정보를 담은 테이블입니다. ANIMAL_INS 테이블 구조는 다음과 같으며, ANIMAL_ID, ANIMAL_TYPE, DATETIME, INTAKE_CONDITION, NAME, SEX_UPON_INTAKE는 각각 동물의 아이디 programmers.co.kr 코드 SELECT.. 2022. 1. 19.
알고리즘(C++) / 프로그래머스 level 3 : 스티커 모으기(2) 프로그래머스 level 3 : 스티커 모으기(2) https://programmers.co.kr/learn/courses/30/lessons/12971 코딩테스트 연습 - 스티커 모으기(2) N개의 스티커가 원형으로 연결되어 있습니다. 다음 그림은 N = 8인 경우의 예시입니다. 원형으로 연결된 스티커에서 몇 장의 스티커를 뜯어내어 뜯어낸 스티커에 적힌 숫자의 합이 최대가 되도록 programmers.co.kr 코드 #include #include #include using namespace std; int dp1[100001] = {0,}; //첫번째 스티커 포함 int dp2[100001] = {0,}; //첫버째 스티커 미포함 int solution(vector sticker) { int answe.. 2021. 11. 4.
알고리즘(C++) / 프로그래머스 위클리 챌린지 : 전력망을 둘로 나누기 위클리 챌린지(9주차) : 전력망을 둘로 나누기 https://programmers.co.kr/learn/courses/30/lessons/86971 코딩테스트 연습 - 9주차 9 [[1,3],[2,3],[3,4],[4,5],[4,6],[4,7],[7,8],[7,9]] 3 7 [[1,2],[2,7],[3,7],[3,4],[4,5],[6,7]] 1 programmers.co.kr 코드 //프로그래머스 전력망을 둘로 나누기 #include #include #include #include #include using namespace std; int solution(int n, vector wires) { int answer = 1000001; //연결되어있는 노드 vec에 저장 vector vec(n + 1).. 2021. 10. 6.
알고리즘(C++) / 프로그래머스 level 3 : 단속카메라 level 3 : 단속카메라 https://programmers.co.kr/learn/courses/30/lessons/42884?language=cpp 코딩테스트 연습 - 단속카메라 [[-20,15], [-14,-5], [-18,-13], [-5,-3]] 2 programmers.co.kr 코드 //프로그래머스 단속카메라 #include #include #include #include using namespace std; int solution(vector routes) { int answer = 1; sort(routes.begin(), routes.end()); //빨리 들어가는 순으로 정렬 int temp = 30001; for (int i = 0; i < routes.size(); i++) { .. 2021. 10. 5.
알고리즘(C++) / 프로그래머스 level 3 : 2 x n 타일링 level 3 : 2 x n 타일링 https://programmers.co.kr/learn/courses/30/lessons/12900?language=cpp 코딩테스트 연습 - 2 x n 타일링 가로 길이가 2이고 세로의 길이가 1인 직사각형모양의 타일이 있습니다. 이 직사각형 타일을 이용하여 세로의 길이가 2이고 가로의 길이가 n인 바닥을 가득 채우려고 합니다. 타일을 채울 때는 programmers.co.kr 코드 //프로그래머스 2xn 타일링 #include #include #include using namespace std; int dp[600001]; int DP(int num) { dp[1] = 1; dp[2] = 2; for (int i = 3; i 2021. 10. 2.
알고리즘(C++) / 프로그래머스 level 3 : 최고의 집합 level 3 : 최고의 집합 https://programmers.co.kr/learn/courses/30/lessons/12938?language=cpp 코딩테스트 연습 - 최고의 집합 자연수 n 개로 이루어진 중복 집합(multi set, 편의상 이후에는 "집합"으로 통칭) 중에 다음 두 조건을 만족하는 집합을 최고의 집합이라고 합니다. 각 원소의 합이 S가 되는 수의 집합 위 조건을 만 programmers.co.kr 코드 //프로그래머스 최고의 집합 #include #include #include #include using namespace std; vector solution(int n, int s) { vector answer; //집합을 만들수 없을 때 if (n > s) { answer.p.. 2021. 10. 1.
알고리즘(C++) / 프로그래머스 level 3 : 야근 지수 level 3 : 야근 지수 https://programmers.co.kr/learn/courses/30/lessons/12927?language=cpp 코딩테스트 연습 - 야근 지수 회사원 Demi는 가끔은 야근을 하는데요, 야근을 하면 야근 피로도가 쌓입니다. 야근 피로도는 야근을 시작한 시점에서 남은 일의 작업량을 제곱하여 더한 값입니다. Demi는 N시간 동안 야근 피로도 programmers.co.kr 코드 //프로그래머스 야근 지수 #include #include #include #include #include using namespace std; long long solution(int n, vector works) { long long answer = 0; priority_queue pq;.. 2021. 10. 1.
알고리즘(C++) / 프로그래머스 level 3 : 등굣길 level 3 : 등굣길 https://programmers.co.kr/learn/courses/30/lessons/42898?language=cpp 코딩테스트 연습 - 등굣길 계속되는 폭우로 일부 지역이 물에 잠겼습니다. 물에 잠기지 않은 지역을 통해 학교를 가려고 합니다. 집에서 학교까지 가는 길은 m x n 크기의 격자모양으로 나타낼 수 있습니다. 아래 그림은 m = programmers.co.kr 코드 //프로그래머스 등굣길 #include #include #include using namespace std; int solution(int m, int n, vector puddles) { int visited[101][101] = { 0, }; for (int i = 0; i < puddles.s.. 2021. 9. 29.
알고리즘(C++) / 프로그래머스 level 3 : 정수 삼각형 level 3 : 정수 삼각형 https://programmers.co.kr/learn/courses/30/lessons/43105 코딩테스트 연습 - 정수 삼각형 [[7], [3, 8], [8, 1, 0], [2, 7, 4, 4], [4, 5, 2, 6, 5]] 30 programmers.co.kr 코드 //프로그래머스 정수 삼각형 #include #include #include #include using namespace std; int solution(vector triangle) { int answer = 0; for (int i = 1; i < triangle.size(); i++) { //두번째 줄부터 for (int j = 0; j < triangle[i].size(); j++) { if (.. 2021. 9. 28.
알고리즘(C++) / 프로그래머스 위클리챌린지 : 최소직사각형 위클리챌린지 : 최소직사각형 https://programmers.co.kr/learn/courses/30/lessons/86491?language=cpp 코딩테스트 연습 - 8주차 [[10, 7], [12, 3], [8, 15], [14, 7], [5, 15]] 120 [[14, 4], [19, 6], [6, 16], [18, 7], [7, 11]] 133 programmers.co.kr 코드 //프로그래머스 최소직사각형 #include #include #include #include using namespace std; int solution(vector sizes) { int answer = 0; int max_col = 0; int max_row = 0; for (int i = 0; i < size.. 2021. 9. 27.
알고리즘(C++) / 프로그래머스 level 3 : 가장 긴 팰린드롬 level 3 : 가장 긴 팰린드롬 https://programmers.co.kr/learn/courses/30/lessons/12904?language=cpp 코딩테스트 연습 - 가장 긴 팰린드롬 앞뒤를 뒤집어도 똑같은 문자열을 팰린드롬(palindrome)이라고 합니다. 문자열 s가 주어질 때, s의 부분문자열(Substring)중 가장 긴 팰린드롬의 길이를 return 하는 solution 함수를 완성해 주세요. 예를들 programmers.co.kr 코드 //프로그래머스 가장 긴 팰린드롬 #include #include #include using namespace std; int palindrome(string& s, int left, int right) { while (left >= 0 && r.. 2021. 9. 24.