본문 바로가기
728x90

분류 전체보기230

알고리즘(C++) / 프로그래머스 level 2 : JadenCase 문자열 만들기 level 2 : JadenCase 문자열 만들기 https://programmers.co.kr/learn/courses/30/lessons/12951?language=cpp 코딩테스트 연습 - JadenCase 문자열 만들기 JadenCase란 모든 단어의 첫 문자가 대문자이고, 그 외의 알파벳은 소문자인 문자열입니다. 문자열 s가 주어졌을 때, s를 JadenCase로 바꾼 문자열을 리턴하는 함수, solution을 완성해주세요. 제한 조건 programmers.co.kr 코드 //프로그래머스 JadenCase 문자열 만들기 #include #include #include using namespace std; string solution(string s) { int check = 1; for (int.. 2021. 9. 21.
알고리즘(C++) / 프로그래머스 level 2 : H-Index level 2 : H-Index https://programmers.co.kr/learn/courses/30/lessons/42747?language=cpp 코딩테스트 연습 - H-Index H-Index는 과학자의 생산성과 영향력을 나타내는 지표입니다. 어느 과학자의 H-Index를 나타내는 값인 h를 구하려고 합니다. 위키백과1에 따르면, H-Index는 다음과 같이 구합니다. 어떤 과학자가 발표 programmers.co.kr 코드 //프로그래머스 H-Index #include #include #include #include using namespace std; int solution(vector citations) { int answer = 0; sort(citations.begin(), cita.. 2021. 9. 17.
알고리즘(C++) / 프로그래머스 level 2 : 소수 찾기 level 2 : 소수 찾기 https://programmers.co.kr/learn/courses/30/lessons/42839?language=cpp 코딩테스트 연습 - 소수 찾기 한자리 숫자가 적힌 종이 조각이 흩어져있습니다. 흩어진 종이 조각을 붙여 소수를 몇 개 만들 수 있는지 알아내려 합니다. 각 종이 조각에 적힌 숫자가 적힌 문자열 numbers가 주어졌을 때, 종이 programmers.co.kr 코드 //프로그래머스 소수찾기 #include #include #include #include #include #include using namespace std; //소수 판별 bool prime(int num) { if (num < 2) return false; for (int i = 2; i 2021. 9. 16.
알고리즘(C++) / 프로그래머스 level 1 : 제일 작은 수 제거하기 level 1 : 제일 작은 수 제거하기 https://programmers.co.kr/learn/courses/30/lessons/12935?language=cpp 코딩테스트 연습 - 제일 작은 수 제거하기 정수를 저장한 배열, arr 에서 가장 작은 수를 제거한 배열을 리턴하는 함수, solution을 완성해주세요. 단, 리턴하려는 배열이 빈 배열인 경우엔 배열에 -1을 채워 리턴하세요. 예를들어 arr이 [4,3,2,1 programmers.co.kr 코드 //프로그래머스 제일 작은 수 제거하기 #include #include #include #include using namespace std; vector solution(vector arr) { vector answer; int min = *mi.. 2021. 9. 15.
알고리즘(C++) / 프로그래머스 위클리 챌린지 7주차 : 입실 퇴실 위클리 챌린지 7주차 : 입실 퇴실 https://programmers.co.kr/learn/courses/30/lessons/86048?language=cpp# 코딩테스트 연습 - 7주차 사회적 거리두기를 위해 회의실에 출입할 때 명부에 이름을 적어야 합니다. 입실과 퇴실이 동시에 이뤄지는 경우는 없으며, 입실 시각과 퇴실 시각은 따로 기록하지 않습니다. 오늘 회의실에는 programmers.co.kr 코드 //프로그래머스 7주차 입실 퇴실 #include #include #include #include using namespace std; vector solution(vector enter, vector leave) { vector answer(enter.size() + 1); vector inout.. 2021. 9. 14.
알고리즘(C++) / 프로그래머스 위클리 챌린지 6주차 : 복서 정렬하기 위클리 챌린지 6주차 : 복서 정렬하기 https://programmers.co.kr/learn/courses/30/lessons/85002?language=cpp 코딩테스트 연습 - 6주차_복서 정렬하기 복서 선수들의 몸무게 weights와, 복서 선수들의 전적을 나타내는 head2head가 매개변수로 주어집니다. 복서 선수들의 번호를 다음과 같은 순서로 정렬한 후 return 하도록 solution 함수를 완성해주세요 programmers.co.kr 코드 //프로그래머스 6주차 복서 정렬하기 #include #include #include #include using namespace std; struct Person { int num = 0; //자신 번호 int weight = 0; //자신 몸무게.. 2021. 9. 14.
알고리즘(C++) / 프로그래머스 level 3 : 불량 사용자 level 3 : 불량 사용자 https://programmers.co.kr/learn/courses/30/lessons/64064?language=cpp 코딩테스트 연습 - 불량 사용자 개발팀 내에서 이벤트 개발을 담당하고 있는 "무지"는 최근 진행된 카카오이모티콘 이벤트에 비정상적인 방법으로 당첨을 시도한 응모자들을 발견하였습니다. 이런 응모자들을 따로 모아 불량 programmers.co.kr 코드 //프로그래머스 불량 사용자 #include #include #include #include using namespace std; bool visited[8]; set s; //중복 포함 x void DFS(vector& user_id, vector& banned_id, int index) { if (i.. 2021. 9. 10.
알고리즘(C++) / 프로그래머스 level 3 : 자물쇠와 열쇠 level 3 : 자물쇠와 열쇠 https://programmers.co.kr/learn/courses/30/lessons/60059?language=cpp 코딩테스트 연습 - 자물쇠와 열쇠 [[0, 0, 0], [1, 0, 0], [0, 1, 1]] [[1, 1, 1], [1, 1, 0], [1, 0, 1]] true programmers.co.kr 코드 //프로그래머스 자물쇠와 열쇠 #include #include #include #include #include #include using namespace std; //시계방향 90도 회전 void rotation(vector& key) { vector key_rotation; for (int i = 0; i < key.size(); i++) { ve.. 2021. 9. 7.
알고리즘(C++) / STL : set, multiset STL : set, multiset 2021.09.06 - [알고리즘] - 알고리즘(C++) / 프로그래머스 level 3 : 이중우선순위큐 문제를 풀면서 multiset에 대해 알 수 있었다. set과 multiset에 대해서 공부해본다. set 유일한 원소만을 가질 수 있는 구조로서 수학적으로 집합을 의미한다. key값을 저장할 수 있다. 하지만, key 값이 중복될 수 없다.(multiset은 중복 가능) 자동으로 정렬된다. (defalt는 오름차순) 노드 기반이다. 균형 이진 트리로 구현되어있다. (binary search tree) 빠른 탐색이 가능하다. 임의 접근이 불가능하다. (배열처럼 접근x, iter 반복자로 접근) 생성, 삽입(insert), 삭제(erase), 탐색(find) 등이 가.. 2021. 9. 6.
알고리즘(C++) / 프로그래머스 level 3 : 이중우선순위큐 level 3 : 이중우선순위큐 https://programmers.co.kr/learn/courses/30/lessons/42628?language=cpp 코딩테스트 연습 - 이중우선순위큐 programmers.co.kr 코드 //프로그래머스 이중우선순위큐 #include #include #include #include #include using namespace std; vector solution(vector operations) { vector answer; vector v; for (int i = 0; i > s >> num; if (s == "I".. 2021. 9. 6.
알고리즘(C++) / 프로그래머스 level 2 : 전화번호 목록 level 2 : 전화번호 목록 https://programmers.co.kr/learn/courses/30/lessons/42577?language=cpp 코딩테스트 연습 - 전화번호 목록 전화번호부에 적힌 전화번호 중, 한 번호가 다른 번호의 접두어인 경우가 있는지 확인하려 합니다. 전화번호가 다음과 같을 경우, 구조대 전화번호는 영석이의 전화번호의 접두사입니다. 구조 programmers.co.kr 코드 //프로그래머스 전화번호 목록 #include #include #include #include #include using namespace std; bool cmp(const string& a, const string& b) { return a.size() < b.size(); } bool solu.. 2021. 9. 5.
알고리즘(C++) / 프로그래머스 level 2 : 더 맵게 level 2 : 더 맵게 https://programmers.co.kr/learn/courses/30/lessons/42626?language=cpp 코딩테스트 연습 - 더 맵게 매운 것을 좋아하는 Leo는 모든 음식의 스코빌 지수를 K 이상으로 만들고 싶습니다. 모든 음식의 스코빌 지수를 K 이상으로 만들기 위해 Leo는 스코빌 지수가 가장 낮은 두 개의 음식을 아래와 같 programmers.co.kr 코드 //프로그래머스 더 맵게 #include #include #include #include #include using namespace std; int solution(vector scoville, int K) { int answer = 0; //우선순위 큐 오름차순 정렬 priority_queu.. 2021. 9. 5.