전체 글333 [프로그래머스/C++] 문자열 잘라서 정렬하기 문제문자열 myString이 주어집니다. "x"를 기준으로 해당 문자열을 잘라내 배열을 만든 후 사전순으로 정렬한 배열을 return 하는 solution 함수를 완성해 주세요. 단, 빈 문자열은 반환할 배열에 넣지 않습니다. 솔루션#include #include #include using namespace std;vector solution(string myString) { vector answer; string tmp = ""; for(int i = 0; i 메모헤맸었는데 반례 테스트케이스 "xxxxax" ["a"]를 추가해서 디버깅 후 해결함. 2025. 2. 22. [프로그래머스/C++] 문자열로 변환 문제정수 n이 주어질 때, n을 문자열로 변환하여 return하도록 solution 함수를 완성해주세요. 솔루션#include #include using namespace std;string solution(int n) { return to_string(n);} 2025. 2. 22. [프로그래머스/C++] 배열 만들기 3 문제정수 배열 arr와 2개의 구간이 담긴 배열 intervals가 주어집니다. intervals는 항상 [[a1, b1], [a2, b2]]의 꼴로 주어지며 각 구간은 닫힌 구간입니다. 닫힌 구간은 양 끝값과 그 사이의 값을 모두 포함하는 구간을 의미합니다. 이때 배열 arr의 첫 번째 구간에 해당하는 배열과 두 번째 구간에 해당하는 배열을 앞뒤로 붙여 새로운 배열을 만들어 return 하는 solution 함수를 완성해 주세요. 솔루션#include #include using namespace std;vector solution(vector arr, vector> intervals) { vector answer; for(int i = 0; i https://school.programmer.. 2025. 2. 22. [프로그래머스/C++] 숫자 찾기 문제정수 num과 k가 매개변수로 주어질 때, num을 이루는 숫자 중에 k가 있으면 num의 그 숫자가 있는 자리 수를 return하고 없으면 -1을 return 하도록 solution 함수를 완성해보세요. 솔루션#include #include #include using namespace std;int solution(int num, int k) { if(to_string(num).find(to_string(k))==-1){ return to_string(num).find(to_string(k)); } return to_string(num).find(to_string(k))+1;} https://school.programmers.co.kr/learn/courses/30/le.. 2025. 2. 22. [프로그래머스/C++] 369게임 문제머쓱이는 친구들과 369게임을 하고 있습니다. 369게임은 1부터 숫자를 하나씩 대며 3, 6, 9가 들어가는 숫자는 숫자 대신 3, 6, 9의 개수만큼 박수를 치는 게임입니다. 머쓱이가 말해야하는 숫자 order가 매개변수로 주어질 때, 머쓱이가 쳐야할 박수 횟수를 return 하도록 solution 함수를 완성해보세요. 솔루션#include #include using namespace std;int solution(int order) { int answer = 0; for(auto c:to_string(order)){ if(c == '3' || c == '6' || c == '9'){ answer += 1; } } return an.. 2025. 2. 22. [프로그래머스/C++] 배열 회전시키기 문제정수가 담긴 배열 numbers와 문자열 direction가 매개변수로 주어집니다. 배열 numbers의 원소를 direction방향으로 한 칸씩 회전시킨 배열을 return하도록 solution 함수를 완성해주세요. 솔루션#include #include using namespace std;vector solution(vector numbers, string direction) { vector answer; if(direction == "right"){ answer.push_back(numbers[numbers.size()-1]); for(int i = 0; i https://school.programmers.co.kr/learn/courses/30/lessons.. 2025. 2. 22. [프로그래머스/C++] 외계행성의 나이 문제우주여행을 하던 머쓱이는 엔진 고장으로 PROGRAMMERS-962 행성에 불시착하게 됐습니다. 입국심사에서 나이를 말해야 하는데, PROGRAMMERS-962 행성에서는 나이를 알파벳으로 말하고 있습니다. a는 0, b는 1, c는 2, ..., j는 9입니다. 예를 들어 23살은 cd, 51살은 fb로 표현합니다. 나이 age가 매개변수로 주어질 때 PROGRAMMER-962식 나이를 return하도록 solution 함수를 완성해주세요. 솔루션#include #include using namespace std;string solution(int age) { string answer = ""; string age_str = to_string(age); for(auto c:age_.. 2025. 2. 22. [프로그래머스/C++] 피자 나눠 먹기 (2) 문제머쓱이네 피자가게는 피자를 여섯 조각으로 잘라 줍니다. 피자를 나눠먹을 사람의 수 n이 매개변수로 주어질 때, n명이 주문한 피자를 남기지 않고 모두 같은 수의 피자 조각을 먹어야 한다면 최소 몇 판을 시켜야 하는지를 return 하도록 solution 함수를 완성해보세요. 솔루션#include #include using namespace std;int solution(int n) { int answer = n; while(1){ if(answer%6==0){ return answer/6; } answer+=n; }} https://school.programmers.co.kr/learn/courses/30/lessons/1208.. 2025. 2. 21. [프로그래머스/C++] 문자열 붙여서 출력하기 문제두 개의 문자열 str1, str2가 공백으로 구분되어 입력으로 주어집니다. 입출력 예와 같이 str1과 str2을 이어서 출력하는 코드를 작성해 보세요. 솔루션#include #include using namespace std;int main(void) { string str1, str2; cin >> str1 >> str2; cout https://school.programmers.co.kr/learn/courses/30/lessons/181946 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 2025. 2. 21. [프로그래머스/C++] flag에 따라 다른 값 반환하기 문제두 정수 a, b와 boolean 변수 flag가 매개변수로 주어질 때, flag가 true면 a + b를 false면 a - b를 return 하는 solution 함수를 작성해 주세요. 솔루션#include #include using namespace std;int solution(int a, int b, bool flag) { if(flag) return a+b; else{ return a-b; }} https://school.programmers.co.kr/learn/courses/30/lessons/181933 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.c.. 2025. 2. 21. 이전 1 2 3 4 5 6 ··· 34 다음