본문 바로가기

전체 글333

[프로그래머스/C++] 중복된 문자 제거 문제문자열 my_string이 매개변수로 주어집니다. my_string에서 중복된 문자를 제거하고 하나의 문자만 남긴 문자열을 return하도록 solution 함수를 완성해주세요. 솔루션#include #include using namespace std;string solution(string my_string) { string answer = ""; for(int i = 0; i  https://school.programmers.co.kr/learn/courses/30/lessons/120888 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 2025. 3. 6.
[프로그래머스/C++] 문자열 섞기 문제길이가 같은 두 문자열 str1과 str2가 주어집니다. 두 문자열의 각 문자가 앞에서부터 서로 번갈아가면서 한 번씩 등장하는 문자열을 만들어 return 하는 solution 함수를 완성해 주세요. 솔루션#include #include using namespace std;string solution(string str1, string str2) { string answer = ""; for(int i = 0; i  https://school.programmers.co.kr/learn/courses/30/lessons/181942 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 2025. 3. 6.
[프로그래머스/C++] 배열의 길이를 2의 거듭제곱으로 만들기 문제정수 배열 arr이 매개변수로 주어집니다. arr의 길이가 2의 정수 거듭제곱이 되도록 arr 뒤에 정수 0을 추가하려고 합니다. arr에 최소한의 개수로 0을 추가한 배열을 return 하는 solution 함수를 작성해 주세요. 솔루션#include #include using namespace std;vector solution(vector arr) { vector answer; int n = 1; while(1){ if(n >= arr.size()){ break; } n *= 2; } for(int i = 0; i  https://school.programmers.co.kr/learn/courses.. 2025. 2. 22.
[프로그래머스/C++] 등차수열의 특정한 항만 더하기 문제두 정수 a, d와 길이가 n인 boolean 배열 included가 주어집니다. 첫째항이 a, 공차가 d인 등차수열에서 included[i]가 i + 1항을 의미할 때, 이 등차수열의 1항부터 n항까지 included가 true인 항들만 더한 값을 return 하는 solution 함수를 작성해 주세요. 솔루션#include #include using namespace std;int solution(int a, int d, vector included) { int answer = 0; int n = a; for(int i = 0; i  https://school.programmers.co.kr/learn/courses/30/lessons/181931 2025. 2. 22.
[프로그래머스/C++] 글자 지우기 문제문자열 my_string과 정수 배열 indices가 주어질 때, my_string에서 indices의 원소에 해당하는 인덱스의 글자를 지우고 이어 붙인 문자열을 return 하는 solution 함수를 작성해 주세요. 솔루션#include #include #include using namespace std;string solution(string my_string, vector indices) { for(auto n:indices){ my_string[n] = '@'; } for(auto n:indices){ my_string.erase(find(my_string.begin(), my_string.end(), '@')); } return my_st.. 2025. 2. 22.
[프로그래머스/C++] 수열과 구간 쿼리 1 문제정수 배열 arr와 2차원 정수 배열 queries이 주어집니다. queries의 원소는 각각 하나의 query를 나타내며, [s, e] 꼴입니다. 각 query마다 순서대로 s ≤ i ≤ e인 모든 i에 대해 arr[i]에 1을 더합니다. 위 규칙에 따라 queries를 처리한 이후의 arr를 return 하는 solution 함수를 완성해 주세요. 솔루션#include #include using namespace std;vector solution(vector arr, vector> queries) { for(int i = 0; i  https://school.programmers.co.kr/learn/courses/30/lessons/181883 프로그래머스SW개발자를 위한 평가, 교육, .. 2025. 2. 22.
[프로그래머스/C++] 합성수 찾기 문제약수의 개수가 세 개 이상인 수를 합성수라고 합니다. 자연수 n이 매개변수로 주어질 때 n이하의 합성수의 개수를 return하도록 solution 함수를 완성해주세요. 솔루션#include #include using namespace std;bool ifcom(int n){ for(int i = 2; i  https://school.programmers.co.kr/learn/courses/30/lessons/120846 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 2025. 2. 22.
[프로그래머스/C++] 날짜 비교하기 문제정수 배열 date1과 date2가 주어집니다. 두 배열은 각각 날짜를 나타내며 [year, month, day] 꼴로 주어집니다. 각 배열에서 year는 연도를, month는 월을, day는 날짜를 나타냅니다. 만약 date1이 date2보다 앞서는 날짜라면 1을, 아니면 0을 return 하는 solution 함수를 완성해 주세요. 솔루션#include #include using namespace std;int solution(vector date1, vector date2) { int answer = 0; for(int i = 0; i date2[i]){ return 0; } } return answer;} 메모처음에는 다음 내용의 코드를 .. 2025. 2. 22.
[프로그래머스/C++] 세로 읽기 문제문자열 my_string과 두 정수 m, c가 주어집니다. my_string을 한 줄에 m 글자씩 가로로 적었을 때 왼쪽부터 세로로 c번째 열에 적힌 글자들을 문자열로 return 하는 solution 함수를 작성해 주세요. 솔루션#include #include using namespace std;string solution(string my_string, int m, int c) { string answer = ""; for(int i = c-1; i  https://school.programmers.co.kr/learn/courses/30/lessons/181904 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프pr.. 2025. 2. 22.
[프로그래머스/C++] ad 제거하기 문제문자열 배열 strArr가 주어집니다. 배열 내의 문자열 중 "ad"라는 부분 문자열을 포함하고 있는 모든 문자열을 제거하고 남은 문자열을 순서를 유지하여 배열로 return 하는 solution 함수를 완성해 주세요. 솔루션#include #include #include using namespace std;vector solution(vector strArr) { vector answer; for(auto s:strArr){ if(s.find("ad") == string::npos){ answer.push_back(s); } } return answer;} https://school.programmers.co.kr/learn/cour.. 2025. 2. 22.