공부/알고리즘 13

코딩테스트 준비하기 좋은 사이트

프로그래머스 고득점 kit https://programmers.co.kr/learn/challenges?tab=algorithm_practice_kit 코딩테스트 연습 기초부터 차근차근, 직접 코드를 작성해 보세요. programmers.co.kr leetcode top interview question (easy, medium, hard) https://leetcode.com/explore/featured/card/top-interview-questions-easy/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are..

공부/알고리즘 2022.06.21

프로그래머스 완전탐색 소수찾기 c++

문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/42839# 코딩테스트 연습 - 소수 찾기 한자리 숫자가 적힌 종이 조각이 흩어져있습니다. 흩어진 종이 조각을 붙여 소수를 몇 개 만들 수 있는지 알아내려 합니다. 각 종이 조각에 적힌 숫자가 적힌 문자열 numbers가 주어졌을 때, 종이 programmers.co.kr 코드 #include #include #include #include using namespace std; map M; bool isPrime(string num){ int n = stoi(num); if(M[n]) return false; // 이미 확인한 수라면 중복이기 때문에 false 리턴 M[n] = true; if(n =..

공부/알고리즘 2022.03.31

2020 카카오 코딩테스트 문자열 압축 c++ solution

#include using namespace std; int solution(string s) { int answer = s.size(); for(int i=1; i 1) zip += to_string(count); zip += temp; answer = answer < zip.size() ? answer : zip.size(); } return answer; } 압축한 문자열을 새로 만들 생각을 못하고, 기존의 문자열을 수정할 생각에 갇혀서 못풀었다. 결국 다른 분의 솔루션을 보고 풀었다. zip 변수가 그것이다. 참고 : https://yjyoon-dev.github.io/kakao/2020/11/05/kakao-strzip/

공부/알고리즘 2021.09.10

2021 카카오 코딩테스트 신규 아이디 추천 c++ solution

#include #include #include using namespace std; string solution(string new_id) { string answer = ""; // 1. 소문자로 for(auto n : new_id) answer += tolower(n); // 2. 잘못된 문자 제거 int size = answer.size(); for(int i=0; i 'z') && (a '9') && a != '-' && a != '_' && a != '.'){ answer.erase(i, 1); i--; size--; } } // 3. 연속된 '.' 치환 size = answer.size(); bool flag = false; for(int i=0; i= 16){ ans..

공부/알고리즘 2021.09.09

HackerRank Bigger is Greater c++ solution

#include #include using namespace std; string biggerIsGreater(string w) { vector V; for(auto s : w) V.push_back(s); do{ string temp=""; for(auto v : V) temp += v; if( temp > w ){ return temp; } }while(next_permutation(V.begin(), V.end())); return "no answer"; } vector에 주어진 문자열을 char로 쪼개어 넣고, next_permutation을 이용하여 다음 크기의 문자열을 얻어서 원 string과 비교하면 된다.

공부/알고리즘 2021.09.07

프로그래머스 가장 큰 수 c++ solution

#include #include #include using namespace std; bool myfunc(string a, string b){ return a+b > b+a ? true : false; } string solution(vector numbers) { string answer = ""; vector v; for(auto n : numbers) v.push_back(to_string(n)); sort(v.begin(), v.end(), myfunc); if(v.at(0) == "0") return "0"; for(auto b : v){ answer += b; } return answer; } https://mungto.tistory.com/22 가장 큰 수 C++ (정렬)[프로그래머스] ※..

공부/알고리즘 2021.09.05