본문 바로가기

전체 글333

[프로그래머스/C++] A로 B 만들기 문제문자열 before와 after가 매개변수로 주어질 때, before의 순서를 바꾸어 after를 만들 수 있으면 1을, 만들 수 없으면 0을 return 하도록 solution 함수를 완성해보세요. 솔루션#include #include #include using namespace std;int solution(string before, string after) { int answer = 0; sort(before.begin(), before.end()); sort(after.begin(), after.end()); if(before == after){ return 1; } return answer;} https://school.programmers.co... 2025. 3. 6.
[프로그래머스/C++] k의 개수 문제1부터 13까지의 수에서, 1은 1, 10, 11, 12, 13 이렇게 총 6번 등장합니다. 정수 i, j, k가 매개변수로 주어질 때, i부터 j까지 k가 몇 번 등장하는지 return 하도록 solution 함수를 완성해주세요. 솔루션#include #include using namespace std;int solution(int i, int j, int k) { int answer = 0; for(int n = i; n  https://school.programmers.co.kr/learn/courses/30/lessons/120887 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 2025. 3. 6.
[프로그래머스/C++] 수열과 구간 쿼리 3 문제정수 배열 arr와 2차원 정수 배열 queries이 주어집니다. queries의 원소는 각각 하나의 query를 나타내며, [i, j] 꼴입니다. 각 query마다 순서대로 arr[i]의 값과 arr[j]의 값을 서로 바꿉니다. 위 규칙에 따라 queries를 처리한 이후의 arr를 return 하는 solution 함수를 완성해 주세요. 솔루션#include #include using namespace std;vector solution(vector arr, vector> queries) { vector answer; for(int i = 0; i  https://school.programmers.co.kr/learn/courses/30/lessons/181924 프로그래머스SW개발자를.. 2025. 3. 6.
[프로그래머스/C++] 배열 만들기 5 문제문자열 배열 intStrs와 정수 k, s, l가 주어집니다. intStrs의 원소는 숫자로 이루어져 있습니다. 배열 intStrs의 각 원소마다 s번 인덱스에서 시작하는 길이 l짜리 부분 문자열을 잘라내 정수로 변환합니다. 이때 변환한 정수값이 k보다 큰 값들을 담은 배열을 return 하는 solution 함수를 완성해 주세요. 솔루션#include #include using namespace std;vector solution(vector intStrs, int k, int s, int l) { vector answer; for(int i = 0; i k){ answer.push_back(stoi(intStrs[i].substr(s,l))); } .. 2025. 3. 6.
[프로그래머스/C++] 문자열 뒤집기 문제문자열 my_string과 정수 s, e가 매개변수로 주어질 때, my_string에서 인덱스 s부터 인덱스 e까지를 뒤집은 문자열을 return 하는 solution 함수를 작성해 주세요. 솔루션#include #include #include using namespace std;string solution(string my_string, int s, int e) { string answer = ""; answer += my_string.substr(0,s); string tmp = my_string.substr(s,e-s+1); reverse(tmp.begin(), tmp.end()); answer += tmp; answer += my_string.substr(e+1.. 2025. 3. 6.
[프로그래머스/C++] 1로 만들기 문제정수가 있을 때, 짝수라면 반으로 나누고, 홀수라면 1을 뺀 뒤 반으로 나누면, 마지막엔 1이 됩니다. 예를 들어 10이 있다면 다음과 같은 과정으로 1이 됩니다. 10 / 2 = 5 (5 - 1) / 2 = 2 2 / 2 = 1 위와 같이 3번의 나누기 연산으로 1이 되었습니다. 정수들이 담긴 리스트 num_list가 주어질 때, num_list의 모든 원소를 1로 만들기 위해서 필요한 나누기 연산의 횟수를 return하도록 solution 함수를 완성해주세요. 솔루션#include #include using namespace std;int solution(vector num_list) { int answer = 0; for(auto n:num_list){ while(1){ .. 2025. 3. 6.
[프로그래머스/C++] 특정 문자열로 끝나는 가장 긴 부분 문자열 찾기 문제문자열 myString과 pat가 주어집니다. myString의 부분 문자열중 pat로 끝나는 가장 긴 부분 문자열을 찾아서 return 하는 solution 함수를 완성해 주세요. 솔루션#include #include using namespace std;string solution(string myString, string pat) { string answer = ""; for(int i = 0; i  https://school.programmers.co.kr/learn/courses/30/lessons/181872 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 2025. 3. 6.
[프로그래머스/C++] 문자열이 몇 번 등장하는지 세기 문제문자열 myString과 pat이 주어집니다. myString에서 pat이 등장하는 횟수를 return 하는 solution 함수를 완성해 주세요. 솔루션#include #include using namespace std;int solution(string myString, string pat) { int answer = 0; for(int i = 0; i  https://school.programmers.co.kr/learn/courses/30/lessons/181871 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 2025. 3. 6.
[프로그래머스/C++] 2차원으로 만들기 문제정수 배열 num_list와 정수 n이 매개변수로 주어집니다. num_list를 다음 설명과 같이 2차원 배열로 바꿔 return하도록 solution 함수를 완성해주세요. num_list가 [1, 2, 3, 4, 5, 6, 7, 8] 로 길이가 8이고 n이 2이므로 num_list를 2 * 4 배열로 다음과 같이 변경합니다. 2차원으로 바꿀 때에는 num_list의 원소들을 앞에서부터 n개씩 나눠 2차원 배열로 변경합니다. 솔루션#include #include using namespace std;vector> solution(vector num_list, int n) { vector> answer; for(int i = 0; i tmp; for(int j = i; j  ht.. 2025. 3. 6.
[프로그래머스/C++] 이차원 배열 대각선 순회하기 문제2차원 정수 배열 board와 정수 k가 주어집니다. i + j  솔루션#include #include using namespace std;int solution(vector> board, int k) { int answer = 0; for(int x = 0; x  https://school.programmers.co.kr/learn/courses/30/lessons/181829 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 2025. 3. 6.