목록Problem Solving (223)
Life Engineering
https://programmers.co.kr/learn/courses/30/lessons/17680 cache 벡터를 갱신해주기(이때 갱신이란 pair 값을 i 값(cities에서 순서)으로 변경) cache miss 일 경우 => 빈 공간 없고, cache size가 0이 아닌 경우: cache 벡터를 sorting 한 후 가장 첫번째 값을 해당 city와 i 로 갱신 빈 공간 있을 경우: cache 벡터에 해당 city, i 를 넣어주기 대.소문자 구분 없으므로 city를 소문자나 대문자로 변경해주고 시작해야된다. 다른 분들의 코드를 보니 이런 식으로도 소문자 변경이 가능하다. transform(it->begin(), it->end(), it->begin(), ::tolower); 또한 pair를 ..
https://programmers.co.kr/learn/courses/30/lessons/42584 코딩테스트 연습 - 주식가격 초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요. 제한사항 prices의 각 가격은 1 이상 10,00 programmers.co.kr #include #include #include using namespace std; vector solution(vector prices) { vector answer(prices.size()); stack s; for (int i=0; iprices[i]){ //내려갔을 때 answer[s.top()]=i-s.top(..
https://programmers.co.kr/learn/courses/30/lessons/70129 코딩테스트 연습 - 이진 변환 반복하기 programmers.co.kr #include #include #include using namespace std; int zero=0; int cnt=0; int stepOne(string s){ int c=0; for (char i : s){ if (i=='0') zero++; else c++; } return c; } string stepTwo(int c){ string temp=""; while (true){ temp+=to_string(c%2); c=c/2; if (c==0) break; } reverse(temp.begin(), temp.end()); ..
https://www.acmicpc.net/problem/1038 1038번: 감소하는 수 음이 아닌 정수 X의 자릿수가 가장 큰 자릿수부터 작은 자릿수까지 감소한다면, 그 수를 감소하는 수라고 한다. 예를 들어, 321과 950은 감소하는 수지만, 322와 958은 아니다. N번째 감소하는 수를 www.acmicpc.net #include #include using namespace std; int N; int answer = 9; long long ans = -1; void backtracking(int n, int cnt, int jarisu, string s) { if (cnt == jarisu) { answer++; if (answer == N) { ans = stoll(s); } return;..