본문 바로가기

Coding Test190

[Programmers] Lv 2. 행렬의 곱셈 https://school.programmers.co.kr/learn/courses/30/lessons/12949 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include using namespace std; vector solution(vector arr1, vector arr2) { vector answer; for (int i = 0; i < arr1.size(); i++) //arr1 { vector tmp; for (int j = 0; j < arr2[0].size(); j++) //arr2 { int value = 0; f.. 2023. 6. 14.
[Programmers] (월간 코드 챌린지 시즌3) Lv 2. n^2 배열 자르기 https://school.programmers.co.kr/learn/courses/30/lessons/87390 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include using namespace std; vector solution(int n, long long left, long long right) { vector answer; // 굳이 2차원 배열을 만들어서 모든 값을 초기화할 필요는 없다. // left와 right 까지의 필요한 공간만을 n으로 행열을 계산해서 도출할 수 있다. for (long i = left; i .. 2023. 6. 13.
[Programmers] Lv 2. 연속 부분 수열 합의 개수 https://school.programmers.co.kr/learn/courses/30/lessons/131701 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include using namespace std; int solution(vector elements) { vector v = elements; set s(elements.begin(), elements.end()); for (int i = 1; i < v.size(); ++i) // 위에서 선언할 때, 길이가 1인 연속부분수열은 계산했으니 1부터 시작 { f.. 2023. 6. 12.
[Programmers] (정렬) Lv 2. H-Index https://school.programmers.co.kr/learn/courses/30/lessons/42747 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include using namespace std; int solution(vector citations) { sort(citations.begin(), citations.end(), greater()); // 내림차순 정렬 // 인덱스가 값보다 크다면, 그 전 인덱스를 리턴 for (int i = 0; i < citations.size(); ++i) { if (.. 2023. 6. 11.
[Programmers] (월간 코드 챌린지 시즌2) Lv 2. 괄호 회전하기 https://school.programmers.co.kr/learn/courses/30/lessons/76502# 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include using namespace std; int solution(string s) { int answer = 0; for (auto iter = s.begin(); iter != s.end(); ++iter) { string temp = s; stack st; // 후입선출로 괄호가 올바른지 체크 int start = iter - s.begin(); .. 2023. 6. 10.
[Programmers] Lv 2. 귤 고르기 https://school.programmers.co.kr/learn/courses/30/lessons/138476?language=cpp 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include #include using namespace std; int solution(int k, vector tangerine) { int answer = 0; map m; // map에 개수만큼 저장 for_each(tangerine.begin(), tangerine.end(), [&](const auto& el) { m[el]+.. 2023. 6. 7.
[Programmers] Lv 2. 멀리 뛰기 https://school.programmers.co.kr/learn/courses/30/lessons/12914 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include long long solution(int n) { long long arr[2001] = { 1, 1 }; for (int i = 2; i 2023. 6. 2.
[Programmers] Lv 2. N개의 최소공배수 ttps://school.programmers.co.kr/learn/courses/30/lessons/12953 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include using namespace std; int solution(vector arr) { int loop = 1; // 첫번째 원소를 기준으로 최소공배수를 구함. // 다른 원소가 (첫번째 원소 * loop)를 나눈 나머지 값이 있으면 공배수가 아닌 것으로 판단. while (::any_of(arr.begin(), arr.end(), [=](const a.. 2023. 6. 1.
[Programmers] (Summer/Winter Coding(~2018)) Lv 2. 점프와 순간 이동 https://school.programmers.co.kr/learn/courses/30/lessons/12980 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include using namespace std; int solution(int n) { int ans = 1; // 이진법에서 1의 수가 총 점프 수. while (n / 2) { if (n % 2) // 홀수일 경우 { --n; ++ans; } n /= 2; } return ans; } GitHub : https://github.com/developeSHG/Algorithm-Baekjoon.. 2023. 5. 31.
[Programmers] (2017 팁스타운) Lv 2. 예상 대진표 https://school.programmers.co.kr/learn/courses/30/lessons/12985 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include using namespace std; class Command { public: Command(const int& a, const int& b) : _a(a), _b(b) { } const bool operator() () { return _a != _b; } public: void vs() { _a = (_a + 1) >> 1; _b = (_b +.. 2023. 5. 31.